remove null option from uriPersonCache

This commit is contained in:
Hazelnoot 2025-09-15 18:26:40 -04:00
parent 00e7473f1c
commit 0047396cf2

View file

@ -34,8 +34,8 @@ export interface FollowStats {
@Injectable() @Injectable()
export class CacheService implements OnApplicationShutdown { export class CacheService implements OnApplicationShutdown {
public readonly userByIdCache: ManagedQuantumKVCache<MiUser>; public readonly userByIdCache: ManagedQuantumKVCache<MiUser>;
public readonly nativeTokenCache: ManagedQuantumKVCache<string | null>; // Token -> UserId public readonly nativeTokenCache: ManagedQuantumKVCache<string>; // Token -> UserId
public readonly uriPersonCache: ManagedQuantumKVCache<string | null>; // URI -> UserId public readonly uriPersonCache: ManagedQuantumKVCache<string>; // URI -> UserId
public readonly userByAcctCache: ManagedQuantumKVCache<string>; // Acct -> UserId public readonly userByAcctCache: ManagedQuantumKVCache<string>; // Acct -> UserId
public readonly userProfileCache: ManagedQuantumKVCache<MiUserProfile>; public readonly userProfileCache: ManagedQuantumKVCache<MiUserProfile>;
public readonly userMutingsCache: ManagedQuantumKVCache<Set<string>>; public readonly userMutingsCache: ManagedQuantumKVCache<Set<string>>;
@ -139,14 +139,14 @@ export class CacheService implements OnApplicationShutdown {
}); });
this.uriPersonCache = this.cacheManagementService.createQuantumKVCache('uriPerson', { this.uriPersonCache = this.cacheManagementService.createQuantumKVCache('uriPerson', {
lifetime: 1000 * 60 * 5, // 5m lifetime: 1000 * 60 * 30, // 30m
fetcher: async (uri) => { fetcher: async (uri) => {
const user = await this.usersRepository const user = await this.usersRepository
.createQueryBuilder('user') .createQueryBuilder('user')
.select('user.id') .select('user.id')
.where({ uri }) .where({ uri })
.getOne() as { id: string } | null; .getOneOrFail() as { id: string };
return user?.id ?? null; return user.id;
}, },
bulkFetcher: async (uris) => { bulkFetcher: async (uris) => {
const users = await this.usersRepository const users = await this.usersRepository
@ -155,8 +155,7 @@ export class CacheService implements OnApplicationShutdown {
.addSelect('user.uri') .addSelect('user.uri')
.where({ uri: In(uris) }) .where({ uri: In(uris) })
.getMany() as { id: string, uri: string }[]; .getMany() as { id: string, uri: string }[];
const userMap = new Map(users.map(u => [u.uri, u.id])); return users.map(u => [u.uri, u.id]);
return uris.map(uri => [uri, userMap.get(uri) ?? null]);
}, },
}); });