From 1fd9ba8dcbbf0e69c356d73e6e97313230ba09dc Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 22 Dec 2022 08:17:13 +0900 Subject: [PATCH] enhance(server): delete outdated notifications regularly to improve db performance --- CHANGELOG.md | 1 + .../src/queue/processors/CleanProcessorService.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c9f71b28..f7abbd355d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ You should also include the user name that made the change. - Add Cloudflare Turnstile CAPTCHA support @CyberRex0 - Server: improve syslog performance @syuilo - Server: improve note scoring for featured notes @CyberRex0 +- Server: delete outdated notifications regularly to improve db performance @syuilo - Client: use tabler-icons instead of fontawesome to better design @syuilo - Client: Add new gabber kick sounds (thanks for noizenecio) - Client: Compress non-animated PNG files @saschanaz diff --git a/packages/backend/src/queue/processors/CleanProcessorService.ts b/packages/backend/src/queue/processors/CleanProcessorService.ts index 8ca39a9677..4225cf6d7f 100644 --- a/packages/backend/src/queue/processors/CleanProcessorService.ts +++ b/packages/backend/src/queue/processors/CleanProcessorService.ts @@ -1,12 +1,12 @@ import { Inject, Injectable } from '@nestjs/common'; import { In, LessThan, MoreThan } from 'typeorm'; import { DI } from '@/di-symbols.js'; -import type { UserIpsRepository } from '@/models/index.js'; +import type { NotificationsRepository, UserIpsRepository } from '@/models/index.js'; import type { Config } from '@/config.js'; import type Logger from '@/logger.js'; +import { bindThis } from '@/decorators.js'; import { QueueLoggerService } from '../QueueLoggerService.js'; import type Bull from 'bull'; -import { bindThis } from '@/decorators.js'; @Injectable() export class CleanProcessorService { @@ -19,6 +19,9 @@ export class CleanProcessorService { @Inject(DI.userIpsRepository) private userIpsRepository: UserIpsRepository, + @Inject(DI.notificationsRepository) + private notificationsRepository: NotificationsRepository, + private queueLoggerService: QueueLoggerService, ) { this.logger = this.queueLoggerService.logger.createSubLogger('clean'); @@ -32,6 +35,10 @@ export class CleanProcessorService { createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))), }); + this.notificationsRepository.delete({ + createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))), + }); + this.logger.succ('Cleaned.'); done(); }