From 88da09bcf733903988ead3f6b00d5229791d16b5 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 14 Sep 2025 10:11:19 -0400 Subject: [PATCH] implement CacheService.userMutedCache --- packages/backend/src/core/CacheService.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index f125784fe9..a612c07f49 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -37,6 +37,7 @@ export class CacheService implements OnApplicationShutdown { public readonly uriPersonCache: ManagedMemoryKVCache; public readonly userProfileCache: ManagedQuantumKVCache; public readonly userMutingsCache: ManagedQuantumKVCache>; + public readonly userMutedCache: ManagedQuantumKVCache>; public readonly userBlockingCache: ManagedQuantumKVCache>; public readonly userBlockedCache: ManagedQuantumKVCache>; // NOTE: 「被」Blockキャッシュ public readonly userListMembershipsCache: ManagedQuantumKVCache>; @@ -130,6 +131,19 @@ export class CacheService implements OnApplicationShutdown { .then(ms => ms.map(m => [m.muterId, new Set(m.muteeIds)])), }); + this.userMutedCache = this.cacheManagementService.createQuantumKVCache>('userMuted', { + lifetime: 1000 * 60 * 30, // 30m + fetcher: (key) => this.mutingsRepository.find({ where: { muteeId: key }, select: ['muterId'] }).then(xs => new Set(xs.map(x => x.muterId))), + bulkFetcher: muteeIds => this.mutingsRepository + .createQueryBuilder('muting') + .select('"muting"."muteeId"', 'muteeId') + .addSelect('array_agg("muting"."muterId")', 'muterIds') + .where({ muteeId: In(muteeIds) }) + .groupBy('muting.muteeId') + .getRawMany<{ muteeId: string, muterIds: string[] }>() + .then(ms => ms.map(m => [m.muteeId, new Set(m.muterIds)])), + }); + this.userBlockingCache = this.cacheManagementService.createQuantumKVCache>('userBlocking', { lifetime: 1000 * 60 * 30, // 30m fetcher: (key) => this.blockingsRepository.find({ where: { blockerId: key }, select: ['blockeeId'] }).then(xs => new Set(xs.map(x => x.blockeeId))), @@ -394,6 +408,7 @@ export class CacheService implements OnApplicationShutdown { await Promise.all([ this.userProfileCache.deleteMany(ids), this.userMutingsCache.deleteMany(ids), + this.userMutedCache.deleteMany(ids), this.userBlockingCache.deleteMany(ids), this.userBlockedCache.deleteMany(ids), this.renoteMutingsCache.deleteMany(ids),