diff options
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
| -rw-r--r-- | packages/backend/src/core/CacheService.ts | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index 02bda436cf..15be5f398c 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -5,9 +5,9 @@ import { Inject, Injectable } from '@nestjs/common'; import * as Redis from 'ioredis'; -import type { BlockingsRepository, ChannelFollowingsRepository, FollowingsRepository, MutingsRepository, RenoteMutingsRepository, UserProfile, UserProfilesRepository, UsersRepository } from '@/models/index.js'; +import type { BlockingsRepository, ChannelFollowingsRepository, FollowingsRepository, MutingsRepository, RenoteMutingsRepository, MiUserProfile, UserProfilesRepository, UsersRepository } from '@/models/index.js'; import { MemoryKVCache, RedisKVCache } from '@/misc/cache.js'; -import type { LocalUser, User } from '@/models/entities/User.js'; +import type { MiLocalUser, MiUser } from '@/models/entities/User.js'; import { DI } from '@/di-symbols.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { bindThis } from '@/decorators.js'; @@ -16,11 +16,11 @@ import type { OnApplicationShutdown } from '@nestjs/common'; @Injectable() export class CacheService implements OnApplicationShutdown { - public userByIdCache: MemoryKVCache<User, User | string>; - public localUserByNativeTokenCache: MemoryKVCache<LocalUser | null, string | null>; - public localUserByIdCache: MemoryKVCache<LocalUser>; - public uriPersonCache: MemoryKVCache<User | null, string | null>; - public userProfileCache: RedisKVCache<UserProfile>; + public userByIdCache: MemoryKVCache<MiUser, MiUser | string>; + public localUserByNativeTokenCache: MemoryKVCache<MiLocalUser | null, string | null>; + public localUserByIdCache: MemoryKVCache<MiLocalUser>; + public uriPersonCache: MemoryKVCache<MiUser | null, string | null>; + public userProfileCache: RedisKVCache<MiUserProfile>; public userMutingsCache: RedisKVCache<Set<string>>; public userBlockingCache: RedisKVCache<Set<string>>; public userBlockedCache: RedisKVCache<Set<string>>; // NOTE: 「被」Blockキャッシュ @@ -60,14 +60,14 @@ export class CacheService implements OnApplicationShutdown { ) { //this.onMessage = this.onMessage.bind(this); - const localUserByIdCache = new MemoryKVCache<LocalUser>(1000 * 60 * 60 * 6 /* 6h */); + const localUserByIdCache = new MemoryKVCache<MiLocalUser>(1000 * 60 * 60 * 6 /* 6h */); this.localUserByIdCache = localUserByIdCache; // ローカルユーザーならlocalUserByIdCacheにデータを追加し、こちらにはid(文字列)だけを追加する - const userByIdCache = new MemoryKVCache<User, User | string>(1000 * 60 * 60 * 6 /* 6h */, { + const userByIdCache = new MemoryKVCache<MiUser, MiUser | string>(1000 * 60 * 60 * 6 /* 6h */, { toMapConverter: user => { if (user.host === null) { - localUserByIdCache.set(user.id, user as LocalUser); + localUserByIdCache.set(user.id, user as MiLocalUser); return user.id; } @@ -77,7 +77,7 @@ export class CacheService implements OnApplicationShutdown { }); this.userByIdCache = userByIdCache; - this.localUserByNativeTokenCache = new MemoryKVCache<LocalUser | null, string | null>(Infinity, { + this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null, string | null>(Infinity, { toMapConverter: user => { if (user === null) return null; @@ -86,7 +86,7 @@ export class CacheService implements OnApplicationShutdown { }, fromMapConverter: id => id === null ? null : localUserByIdCache.get(id), }); - this.uriPersonCache = new MemoryKVCache<User | null, string | null>(Infinity, { + this.uriPersonCache = new MemoryKVCache<MiUser | null, string | null>(Infinity, { toMapConverter: user => { if (user === null) return null; @@ -96,7 +96,7 @@ export class CacheService implements OnApplicationShutdown { fromMapConverter: id => id === null ? null : userByIdCache.get(id), }); - this.userProfileCache = new RedisKVCache<UserProfile>(this.redisClient, 'userProfile', { + this.userProfileCache = new RedisKVCache<MiUserProfile>(this.redisClient, 'userProfile', { lifetime: 1000 * 60 * 30, // 30m memoryCacheLifetime: 1000 * 60, // 1m fetcher: (key) => this.userProfilesRepository.findOneByOrFail({ userId: key }), @@ -178,7 +178,7 @@ export class CacheService implements OnApplicationShutdown { break; } case 'userTokenRegenerated': { - const user = await this.usersRepository.findOneByOrFail({ id: body.id }) as LocalUser; + const user = await this.usersRepository.findOneByOrFail({ id: body.id }) as MiLocalUser; this.localUserByNativeTokenCache.delete(body.oldToken); this.localUserByNativeTokenCache.set(body.newToken, user); break; @@ -197,7 +197,7 @@ export class CacheService implements OnApplicationShutdown { } @bindThis - public findUserById(userId: User['id']) { + public findUserById(userId: MiUser['id']) { return this.userByIdCache.fetch(userId, () => this.usersRepository.findOneByOrFail({ id: userId })); } |