summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-01-10 20:06:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-01-10 20:06:25 +0900
commit33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1 (patch)
treee78e47afbdae6c28866905f91fcd3c4e4498da80
parentMerge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff)
downloadmisskey-33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1.tar.gz
misskey-33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1.tar.bz2
misskey-33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1.zip
perf(server): improve stats api performance
-rw-r--r--CHANGELOG.md1
-rw-r--r--packages/backend/src/server/api/endpoints/stats.ts21
2 files changed, 14 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5607dbf231..8ccb2cd94d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -62,6 +62,7 @@ You should also include the user name that made the change.
- Server: improve syslog performance @syuilo
- Server: improve note scoring for featured notes @CyberRex0
- Server: アンケート選択肢の文字数制限を緩和 @syuilo
+- Server: improve stats api performance @syuilo
- Server: delete outdated notifications regularly to improve db performance @syuilo
- Server: delete outdated hard-mutes regularly to improve db performance @syuilo
- Server: delete outdated notes of antenna regularly to improve db performance @syuilo
diff --git a/packages/backend/src/server/api/endpoints/stats.ts b/packages/backend/src/server/api/endpoints/stats.ts
index 96b22b0261..8bd0311dce 100644
--- a/packages/backend/src/server/api/endpoints/stats.ts
+++ b/packages/backend/src/server/api/endpoints/stats.ts
@@ -3,6 +3,8 @@ import { IsNull } from 'typeorm';
import type { InstancesRepository, NoteReactionsRepository, NotesRepository, UsersRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
+import NotesChart from '@/core/chart/charts/notes.js';
+import UsersChart from '@/core/chart/charts/users.js';
export const meta = {
requireCredential: false,
@@ -66,21 +68,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
@Inject(DI.noteReactionsRepository)
private noteReactionsRepository: NoteReactionsRepository,
+
+ private notesChart: NotesChart,
+ private usersChart: UsersChart,
) {
super(meta, paramDef, async () => {
+ const notesChart = await this.notesChart.getChart('hour', 1, null);
+ const notesCount = notesChart.local.total[0] + notesChart.remote.total[0];
+ const originalNotesCount = notesChart.local.total[0];
+
+ const usersChart = await this.usersChart.getChart('hour', 1, null);
+ const usersCount = usersChart.local.total[0] + usersChart.remote.total[0];
+ const originalUsersCount = usersChart.local.total[0];
+
const [
- notesCount,
- originalNotesCount,
- usersCount,
- originalUsersCount,
reactionsCount,
//originalReactionsCount,
instances,
] = await Promise.all([
- this.notesRepository.count({ cache: 3600000 }), // 1 hour
- this.notesRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
- this.usersRepository.count({ cache: 3600000 }),
- this.usersRepository.count({ where: { host: IsNull() }, cache: 3600000 }),
this.noteReactionsRepository.count({ cache: 3600000 }), // 1 hour
//this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
this.instancesRepository.count({ cache: 3600000 }),