diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-10 20:06:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-10 20:06:25 +0900 |
| commit | 33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1 (patch) | |
| tree | e78e47afbdae6c28866905f91fcd3c4e4498da80 /packages/backend/src/server/api/endpoints/stats.ts | |
| parent | Merge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff) | |
| download | sharkey-33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1.tar.gz sharkey-33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1.tar.bz2 sharkey-33b22a323ceb5fd22d66b5f2cddfd5ec96c60fb1.zip | |
perf(server): improve stats api performance
Diffstat (limited to 'packages/backend/src/server/api/endpoints/stats.ts')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/stats.ts | 21 |
1 files changed, 13 insertions, 8 deletions
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 }), |