summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CacheService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
-rw-r--r--packages/backend/src/core/CacheService.ts46
1 files changed, 7 insertions, 39 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts
index 78bb4f70e9..68f37d0cf9 100644
--- a/packages/backend/src/core/CacheService.ts
+++ b/packages/backend/src/core/CacheService.ts
@@ -16,10 +16,10 @@ import type { OnApplicationShutdown } from '@nestjs/common';
@Injectable()
export class CacheService implements OnApplicationShutdown {
- public userByIdCache: MemoryKVCache<MiUser, MiUser | string>;
- public localUserByNativeTokenCache: MemoryKVCache<MiLocalUser | null, string | null>;
+ public userByIdCache: MemoryKVCache<MiUser>;
+ public localUserByNativeTokenCache: MemoryKVCache<MiLocalUser | null>;
public localUserByIdCache: MemoryKVCache<MiLocalUser>;
- public uriPersonCache: MemoryKVCache<MiUser | null, string | null>;
+ public uriPersonCache: MemoryKVCache<MiUser | null>;
public userProfileCache: RedisKVCache<MiUserProfile>;
public userMutingsCache: RedisKVCache<Set<string>>;
public userBlockingCache: RedisKVCache<Set<string>>;
@@ -56,42 +56,10 @@ export class CacheService implements OnApplicationShutdown {
) {
//this.onMessage = this.onMessage.bind(this);
- const localUserByIdCache = new MemoryKVCache<MiLocalUser>(1000 * 60 * 60 * 6 /* 6h */);
- this.localUserByIdCache = localUserByIdCache;
-
- // ローカルユーザーならlocalUserByIdCacheにデータを追加し、こちらにはid(文字列)だけを追加する
- const userByIdCache = new MemoryKVCache<MiUser, MiUser | string>(1000 * 60 * 60 * 6 /* 6h */, {
- toMapConverter: user => {
- if (user.host === null) {
- localUserByIdCache.set(user.id, user as MiLocalUser);
- return user.id;
- }
-
- return user;
- },
- fromMapConverter: userOrId => typeof userOrId === 'string' ? localUserByIdCache.get(userOrId) : userOrId,
- });
- this.userByIdCache = userByIdCache;
-
- this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null, string | null>(Infinity, {
- toMapConverter: user => {
- if (user === null) return null;
-
- localUserByIdCache.set(user.id, user);
- return user.id;
- },
- fromMapConverter: id => id === null ? null : localUserByIdCache.get(id),
- });
- this.uriPersonCache = new MemoryKVCache<MiUser | null, string | null>(Infinity, {
- toMapConverter: user => {
- if (user === null) return null;
- if (user.isDeleted) return null;
-
- userByIdCache.set(user.id, user);
- return user.id;
- },
- fromMapConverter: id => id === null ? null : userByIdCache.get(id),
- });
+ this.userByIdCache = new MemoryKVCache<MiUser>(Infinity);
+ this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null>(Infinity);
+ this.localUserByIdCache = new MemoryKVCache<MiLocalUser>(Infinity);
+ this.uriPersonCache = new MemoryKVCache<MiUser | null>(Infinity);
this.userProfileCache = new RedisKVCache<MiUserProfile>(this.redisClient, 'userProfile', {
lifetime: 1000 * 60 * 30, // 30m