From af3258dc79488b73435819e7799eb1515f15a6aa Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 2 Jul 2023 16:02:32 +0900 Subject: perf(backend): make some features optionable Resolve #11064 Resolve #11065 --- packages/backend/src/daemons/ServerStatsService.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'packages/backend/src/daemons/ServerStatsService.ts') diff --git a/packages/backend/src/daemons/ServerStatsService.ts b/packages/backend/src/daemons/ServerStatsService.ts index 6cd71c0e2a..375fd5e516 100644 --- a/packages/backend/src/daemons/ServerStatsService.ts +++ b/packages/backend/src/daemons/ServerStatsService.ts @@ -3,6 +3,7 @@ import si from 'systeminformation'; import Xev from 'xev'; import * as osUtils from 'os-utils'; import { bindThis } from '@/decorators.js'; +import { MetaService } from '@/core/MetaService.js'; import type { OnApplicationShutdown } from '@nestjs/common'; const ev = new Xev(); @@ -14,9 +15,10 @@ const round = (num: number) => Math.round(num * 10) / 10; @Injectable() export class ServerStatsService implements OnApplicationShutdown { - private intervalId: NodeJS.Timer; + private intervalId: NodeJS.Timer | null = null; constructor( + private metaService: MetaService, ) { } @@ -24,7 +26,9 @@ export class ServerStatsService implements OnApplicationShutdown { * Report server stats regularly */ @bindThis - public start(): void { + public async start(): Promise { + if (!(await this.metaService.fetch(true)).enableServerMachineStats) return; + const log = [] as any[]; ev.on('requestServerStatsLog', x => { @@ -64,7 +68,9 @@ export class ServerStatsService implements OnApplicationShutdown { @bindThis public dispose(): void { - clearInterval(this.intervalId); + if (this.intervalId) { + clearInterval(this.intervalId); + } } @bindThis -- cgit v1.2.3-freya