implement CacheService.userMutedCache
This commit is contained in:
parent
e54b8c4b72
commit
88da09bcf7
1 changed files with 15 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ export class CacheService implements OnApplicationShutdown {
|
|||
public readonly uriPersonCache: ManagedMemoryKVCache<MiUser | null>;
|
||||
public readonly userProfileCache: ManagedQuantumKVCache<MiUserProfile>;
|
||||
public readonly userMutingsCache: ManagedQuantumKVCache<Set<string>>;
|
||||
public readonly userMutedCache: ManagedQuantumKVCache<Set<string>>;
|
||||
public readonly userBlockingCache: ManagedQuantumKVCache<Set<string>>;
|
||||
public readonly userBlockedCache: ManagedQuantumKVCache<Set<string>>; // NOTE: 「被」Blockキャッシュ
|
||||
public readonly userListMembershipsCache: ManagedQuantumKVCache<Map<string, MiUserListMembership>>;
|
||||
|
|
@ -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<Set<string>>('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<Set<string>>('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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue