From c5cfbd99d03c88038becfed9d99df5dbb175e154 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 10 Jan 2023 20:08:55 +0900 Subject: [PATCH] perf(server): improve nodeinfo performance Resolve #9505 --- CHANGELOG.md | 1 + .../src/server/NodeinfoServerService.ts | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ccb2cd94d..d2b5ffde3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ You should also include the user name that made the change. - Server: improve note scoring for featured notes @CyberRex0 - Server: アンケート選択肢の文字数制限を緩和 @syuilo - Server: improve stats api performance @syuilo +- Server: improve nodeinfo 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/NodeinfoServerService.ts b/packages/backend/src/server/NodeinfoServerService.ts index 86d87872b2..c4236c8752 100644 --- a/packages/backend/src/server/NodeinfoServerService.ts +++ b/packages/backend/src/server/NodeinfoServerService.ts @@ -8,6 +8,8 @@ import { MAX_NOTE_TEXT_LENGTH } from '@/const.js'; import { Cache } from '@/misc/cache.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { bindThis } from '@/decorators.js'; +import NotesChart from '@/core/chart/charts/notes.js'; +import UsersChart from '@/core/chart/charts/users.js'; import type { FastifyInstance, FastifyPluginOptions } from 'fastify'; const nodeinfo2_1path = '/nodeinfo/2.1'; @@ -27,6 +29,8 @@ export class NodeinfoServerService { private userEntityService: UserEntityService, private metaService: MetaService, + private notesChart: NotesChart, + private usersChart: UsersChart, ) { //this.createServer = this.createServer.bind(this); } @@ -46,20 +50,27 @@ export class NodeinfoServerService { public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) { const nodeinfo2 = async () => { const now = Date.now(); + + const notesChart = await this.notesChart.getChart('hour', 1, null); + const localPosts = notesChart.local.total[0]; + + const usersChart = await this.usersChart.getChart('hour', 1, null); + const total = usersChart.local.total[0]; + const [ meta, - total, - activeHalfyear, - activeMonth, - localPosts, + //activeHalfyear, + //activeMonth, ] = await Promise.all([ this.metaService.fetch(true), - this.usersRepository.count({ where: { host: IsNull() } }), - this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 15552000000)) } }), - this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 2592000000)) } }), - this.notesRepository.count({ where: { userHost: IsNull() } }), + // 重い + //this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 15552000000)) } }), + //this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 2592000000)) } }), ]); + const activeHalfyear = null; + const activeMonth = null; + const proxyAccount = meta.proxyAccountId ? await this.userEntityService.pack(meta.proxyAccountId).catch(() => null) : null; return {