1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-27 14:28:49 +09:00

perf(server): improve stats api performance

This commit is contained in:
syuilo 2023-01-10 20:06:25 +09:00
parent f032fb628a
commit 33b22a323c
2 changed files with 14 additions and 8 deletions

View File

@ -62,6 +62,7 @@ You should also include the user name that made the change.
- Server: improve syslog performance @syuilo - Server: improve syslog performance @syuilo
- Server: improve note scoring for featured notes @CyberRex0 - Server: improve note scoring for featured notes @CyberRex0
- Server: アンケート選択肢の文字数制限を緩和 @syuilo - Server: アンケート選択肢の文字数制限を緩和 @syuilo
- Server: improve stats api performance @syuilo
- Server: delete outdated notifications regularly to improve db 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 hard-mutes regularly to improve db performance @syuilo
- Server: delete outdated notes of antenna regularly to improve db performance @syuilo - Server: delete outdated notes of antenna regularly to improve db performance @syuilo

View File

@ -3,6 +3,8 @@ import { IsNull } from 'typeorm';
import type { InstancesRepository, NoteReactionsRepository, NotesRepository, UsersRepository } from '@/models/index.js'; import type { InstancesRepository, NoteReactionsRepository, NotesRepository, UsersRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js'; import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.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 = { export const meta = {
requireCredential: false, requireCredential: false,
@ -66,21 +68,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
@Inject(DI.noteReactionsRepository) @Inject(DI.noteReactionsRepository)
private noteReactionsRepository: NoteReactionsRepository, private noteReactionsRepository: NoteReactionsRepository,
private notesChart: NotesChart,
private usersChart: UsersChart,
) { ) {
super(meta, paramDef, async () => { 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 [ const [
notesCount,
originalNotesCount,
usersCount,
originalUsersCount,
reactionsCount, reactionsCount,
//originalReactionsCount, //originalReactionsCount,
instances, instances,
] = await Promise.all([ ] = 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({ cache: 3600000 }), // 1 hour
//this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }), //this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
this.instancesRepository.count({ cache: 3600000 }), this.instancesRepository.count({ cache: 3600000 }),