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