diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2024-02-16 15:07:12 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2024-02-16 15:07:12 +0900 |
| commit | f55e1ee13897ed2dadb6dff8af965255a178c724 (patch) | |
| tree | 4bcd452431006c2fcfde52edbddf733588c8628b /packages/backend/src/core/CacheService.ts | |
| parent | リモートユーザーが復活してもキャッシュにより該当ユ... (diff) | |
| download | sharkey-f55e1ee13897ed2dadb6dff8af965255a178c724.tar.gz sharkey-f55e1ee13897ed2dadb6dff8af965255a178c724.tar.bz2 sharkey-f55e1ee13897ed2dadb6dff8af965255a178c724.zip | |
refactor(backend): misc/cacheをシンプルな実装に戻した
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
| -rw-r--r-- | packages/backend/src/core/CacheService.ts | 46 |
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 |