summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-07 21:32:55 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-09 11:02:36 -0400
commit372714c9b603e6e06ac1f0792c96d4066b7413d5 (patch)
treec82d20028e4868197dc48fcae566403b5e550cdf /packages/backend/src/core
parentre-type userFollowingsCache to match the others (diff)
downloadsharkey-372714c9b603e6e06ac1f0792c96d4066b7413d5.tar.gz
sharkey-372714c9b603e6e06ac1f0792c96d4066b7413d5.tar.bz2
sharkey-372714c9b603e6e06ac1f0792c96d4066b7413d5.zip
implement userFollowersCache
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/CacheService.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts
index 38a93e57f4..e8b26f8b9b 100644
--- a/packages/backend/src/core/CacheService.ts
+++ b/packages/backend/src/core/CacheService.ts
@@ -47,6 +47,7 @@ export class CacheService implements OnApplicationShutdown {
public userBlockedCache: QuantumKVCache<Set<string>>; // NOTE: 「被」Blockキャッシュ
public renoteMutingsCache: QuantumKVCache<Set<string>>;
public userFollowingsCache: QuantumKVCache<Map<string, { withReplies: boolean }>>;
+ public userFollowersCache: QuantumKVCache<Set<string>>;
protected userFollowStatsCache = new MemoryKVCache<FollowStats>(1000 * 60 * 10); // 10 minutes
protected translationsCache: RedisKVCache<CachedTranslationEntity>;
@@ -115,6 +116,11 @@ export class CacheService implements OnApplicationShutdown {
fetcher: (key) => this.followingsRepository.find({ where: { followerId: key }, select: ['followeeId', 'withReplies'] }).then(xs => new Map(xs.map(f => [f.followeeId, { withReplies: f.withReplies }]))),
});
+ this.userFollowersCache = new QuantumKVCache<Set<string>>(this.internalEventService, 'userFollowers', {
+ lifetime: 1000 * 60 * 30, // 30m
+ fetcher: (key) => this.followingsRepository.find({ where: { followeeId: key }, select: ['followerId'] }).then(xs => new Set(xs.map(x => x.followerId))),
+ });
+
this.translationsCache = new RedisKVCache<CachedTranslationEntity>(this.redisClient, 'translations', {
lifetime: 1000 * 60 * 60 * 24 * 7, // 1 week,
memoryCacheLifetime: 1000 * 60, // 1 minute
@@ -154,6 +160,7 @@ export class CacheService implements OnApplicationShutdown {
this.userBlockedCache.delete(body.id),
this.renoteMutingsCache.delete(body.id),
this.userFollowingsCache.delete(body.id),
+ this.userFollowersCache.delete(body.id),
]);
}
} else {
@@ -193,7 +200,10 @@ export class CacheService implements OnApplicationShutdown {
if (follower) follower.followingCount++;
const followee = this.userByIdCache.get(body.followeeId);
if (followee) followee.followersCount++;
- await this.userFollowingsCache.delete(body.followerId);
+ await Promise.all([
+ this.userFollowingsCache.delete(body.followerId),
+ this.userFollowersCache.delete(body.followeeId),
+ ]);
this.userFollowStatsCache.delete(body.followerId);
this.userFollowStatsCache.delete(body.followeeId);
break;
@@ -203,7 +213,10 @@ export class CacheService implements OnApplicationShutdown {
if (follower) follower.followingCount--;
const followee = this.userByIdCache.get(body.followeeId);
if (followee) followee.followersCount--;
- await this.userFollowingsCache.delete(body.followerId);
+ await Promise.all([
+ this.userFollowingsCache.delete(body.followerId),
+ this.userFollowersCache.delete(body.followeeId),
+ ]);
this.userFollowStatsCache.delete(body.followerId);
this.userFollowStatsCache.delete(body.followeeId);
break;