From d8dc10829cf0d04842b2261fdc66e680a328e9d7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 7 Sep 2023 16:20:28 +0900 Subject: [PATCH] =?UTF-8?q?enhance(backend):=20=E5=8F=A4=E3=81=84=E3=82=A2?= =?UTF-8?q?=E3=83=B3=E3=83=86=E3=83=8A=E3=82=92=E8=87=AA=E5=8B=95=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E3=81=99=E3=82=8B=E3=81=8B=E5=88=87=E3=82=8A=E6=9B=BF?= =?UTF-8?q?=E3=81=88=E5=8F=AF=E8=83=BD=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolve #11785 --- CHANGELOG.md | 1 + packages/backend/src/config.ts | 3 +++ .../queue/processors/CleanProcessorService.ts | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 540726ae7d..f058786b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ - ファイルアップロード時等にファイル名の拡張子を修正する関数(correctFilename)の挙動を改善 - Webhookのペイロードにサーバーのurlが含まれるようになりました - Webhook設定でsecretを空に出来るように +- 使われていないアンテナの自動停止を設定可能に - Fix: 一部のfeatured noteを照会できない問題を修正 - Fix: muteがapiからのuser list timeline取得で機能しない問題を修正 - Fix: ジョブキュー管理画面の認証を回避できる問題を修正 diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 0113090a08..abbfdfed8f 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -88,6 +88,7 @@ type Source = { perChannelMaxNoteCacheCount?: number; perUserNotificationsMaxCount?: number; + deactivateAntennaThreshold?: number; }; export type Config = { @@ -161,6 +162,7 @@ export type Config = { redisForJobQueue: RedisOptions & RedisOptionsSource; perChannelMaxNoteCacheCount: number; perUserNotificationsMaxCount: number; + deactivateAntennaThreshold: number; }; const _filename = fileURLToPath(import.meta.url); @@ -252,6 +254,7 @@ export function loadConfig(): Config { clientManifestExists: clientManifestExists, perChannelMaxNoteCacheCount: config.perChannelMaxNoteCacheCount ?? 1000, perUserNotificationsMaxCount: config.perUserNotificationsMaxCount ?? 300, + deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7), }; } diff --git a/packages/backend/src/queue/processors/CleanProcessorService.ts b/packages/backend/src/queue/processors/CleanProcessorService.ts index 03a33e76ac..3b974c2405 100644 --- a/packages/backend/src/queue/processors/CleanProcessorService.ts +++ b/packages/backend/src/queue/processors/CleanProcessorService.ts @@ -10,6 +10,7 @@ import type { AntennasRepository, MutedNotesRepository, RoleAssignmentsRepositor import type Logger from '@/logger.js'; import { bindThis } from '@/decorators.js'; import { IdService } from '@/core/IdService.js'; +import type { Config } from '@/config.js'; import { QueueLoggerService } from '../QueueLoggerService.js'; import type * as Bull from 'bullmq'; @@ -18,6 +19,9 @@ export class CleanProcessorService { private logger: Logger; constructor( + @Inject(DI.config) + private config: Config, + @Inject(DI.userIpsRepository) private userIpsRepository: UserIpsRepository, @@ -54,12 +58,14 @@ export class CleanProcessorService { reason: 'word', }); - // 7日以上使われてないアンテナを停止 - this.antennasRepository.update({ - lastUsedAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 7))), - }, { - isActive: false, - }); + // 使われてないアンテナを停止 + if (this.config.deactivateAntennaThreshold > 0) { + this.antennasRepository.update({ + lastUsedAt: LessThan(new Date(Date.now() - this.config.deactivateAntennaThreshold)), + }, { + isActive: false, + }); + } const expiredRoleAssignments = await this.roleAssignmentsRepository.createQueryBuilder('assign') .where('assign.expiresAt IS NOT NULL')