From 98366d1ed58dba064a6ea570d96e59fc67c80de8 Mon Sep 17 00:00:00 2001 From: pen <121443048+penginn-net@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:45:45 +0000 Subject: [PATCH 1/2] purgeFTT --- .../backend/src/core/FanoutTimelineService.ts | 36 +++++++++++++++++-- packages/backend/src/core/MetaService.ts | 3 ++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/FanoutTimelineService.ts b/packages/backend/src/core/FanoutTimelineService.ts index f6dabfadcd..8476885342 100644 --- a/packages/backend/src/core/FanoutTimelineService.ts +++ b/packages/backend/src/core/FanoutTimelineService.ts @@ -14,9 +14,9 @@ export type FanoutTimelineName = | `homeTimeline:${string}` | `homeTimelineWithFiles:${string}` // only notes with files are included // local timeline - | `localTimeline` // replies are not included - | `localTimelineWithFiles` // only non-reply notes with files are included - | `localTimelineWithReplies` // only replies are included + | 'localTimeline' // replies are not included + | 'localTimelineWithFiles' // only non-reply notes with files are included + | 'localTimelineWithReplies' // only replies are included | `localTimelineWithReplyTo:${string}` // Only replies to specific local user are included. Parameter is reply user id. // antenna @@ -111,4 +111,34 @@ export class FanoutTimelineService { public purge(name: FanoutTimelineName) { return this.redisForTimelines.del('list:' + name); } + + @bindThis + public async purgeAllcache() { + const timeLinePatterns = [ + '*list:homeTimeline*', + '*list:localTimeline*', + '*list:antennaTimeline*', + '*list:userTimeline*', + '*list:userListTimeline*', + '*list:channelTimeline*', + '*list:roleTimeline*', + ]; + let timeLines = [] as string[]; + + for (const timeline of timeLinePatterns) { + let cursor = '0'; + do { + const scanResult = await this.redisForTimelines.scan(cursor, 'MATCH', timeline, 'COUNT', 300); + cursor = scanResult[0]; + timeLines = timeLines.concat(scanResult[1]); + scanResult[1].forEach(x => console.log(x)); + } while (cursor !== '0'); + } + + const pipeline = this.redisForTimelines.pipeline(); + for (const timeLine of timeLines) { + pipeline.del(`list:${timeLine.split('list:')[1]}`); + } + await pipeline.exec(); + } } diff --git a/packages/backend/src/core/MetaService.ts b/packages/backend/src/core/MetaService.ts index 3d88d0aefe..02928642de 100644 --- a/packages/backend/src/core/MetaService.ts +++ b/packages/backend/src/core/MetaService.ts @@ -12,6 +12,7 @@ import { GlobalEventService } from '@/core/GlobalEventService.js'; import { bindThis } from '@/decorators.js'; import type { GlobalEvents } from '@/core/GlobalEventService.js'; import { FeaturedService } from '@/core/FeaturedService.js'; +import { FanoutTimelineService } from './FanoutTimelineService.js'; import type { OnApplicationShutdown } from '@nestjs/common'; @Injectable() @@ -28,6 +29,7 @@ export class MetaService implements OnApplicationShutdown { private featuredService: FeaturedService, private globalEventService: GlobalEventService, + private fanoutTimelineService: FanoutTimelineService, ) { //this.onMessage = this.onMessage.bind(this); @@ -112,6 +114,7 @@ export class MetaService implements OnApplicationShutdown { before = metas[0]; if (before) { + if (before.enableFanoutTimeline === true && data.enableFanoutTimeline === false) this.fanoutTimelineService.purgeAllcache(); await transactionalEntityManager.update(MiMeta, before.id, data); const metas = await transactionalEntityManager.find(MiMeta, { From e09ecac7bbecaf95d5b812f67c63b7433be84f11 Mon Sep 17 00:00:00 2001 From: pen <121443048+penginn-net@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:59:21 +0900 Subject: [PATCH 2/2] del log --- packages/backend/src/core/FanoutTimelineService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/src/core/FanoutTimelineService.ts b/packages/backend/src/core/FanoutTimelineService.ts index 8476885342..ca33556fa4 100644 --- a/packages/backend/src/core/FanoutTimelineService.ts +++ b/packages/backend/src/core/FanoutTimelineService.ts @@ -131,7 +131,6 @@ export class FanoutTimelineService { const scanResult = await this.redisForTimelines.scan(cursor, 'MATCH', timeline, 'COUNT', 300); cursor = scanResult[0]; timeLines = timeLines.concat(scanResult[1]); - scanResult[1].forEach(x => console.log(x)); } while (cursor !== '0'); }