From ad4d8b07d3152ae7c9ba71e571de17ca8b638abc Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 22 Dec 2022 08:29:18 +0900 Subject: [PATCH] enhance(server): delete outdated hard-mutes regularly to improve db performance --- CHANGELOG.md | 1 + .../src/queue/processors/CleanProcessorService.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7abbd355d..20db04f3e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ You should also include the user name that made the change. - Server: improve syslog performance @syuilo - Server: improve note scoring for featured notes @CyberRex0 - Server: delete outdated notifications regularly to improve db performance @syuilo +- Server: delete outdated hard-mutes 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 4225cf6d7f..9836065aa7 100644 --- a/packages/backend/src/queue/processors/CleanProcessorService.ts +++ b/packages/backend/src/queue/processors/CleanProcessorService.ts @@ -1,10 +1,11 @@ import { Inject, Injectable } from '@nestjs/common'; import { In, LessThan, MoreThan } from 'typeorm'; import { DI } from '@/di-symbols.js'; -import type { NotificationsRepository, UserIpsRepository } from '@/models/index.js'; +import type { MutedNotesRepository, NotificationsRepository, UserIpsRepository } from '@/models/index.js'; import type { Config } from '@/config.js'; import type Logger from '@/logger.js'; import { bindThis } from '@/decorators.js'; +import { IdService } from '@/core/IdService.js'; import { QueueLoggerService } from '../QueueLoggerService.js'; import type Bull from 'bull'; @@ -22,7 +23,11 @@ export class CleanProcessorService { @Inject(DI.notificationsRepository) private notificationsRepository: NotificationsRepository, + @Inject(DI.mutedNotesRepository) + private mutedNotesRepository: MutedNotesRepository, + private queueLoggerService: QueueLoggerService, + private idService: IdService, ) { this.logger = this.queueLoggerService.logger.createSubLogger('clean'); } @@ -39,6 +44,11 @@ export class CleanProcessorService { createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))), }); + this.mutedNotesRepository.delete({ + id: LessThan(this.idService.genId(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90)))), + reason: 'word', + }); + this.logger.succ('Cleaned.'); done(); }