server: limit caching time for public keys

This commit is contained in:
Johann150 2023-07-19 09:43:17 +02:00
parent 456a86af8d
commit 75ab4de41f
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -5,6 +5,7 @@ import { UserPublickey } from '@/models/entities/user-publickey.js';
import { uriPersonCache, userByIdCache } from '@/services/user-cache.js'; import { uriPersonCache, userByIdCache } from '@/services/user-cache.js';
import { createPerson } from '@/remote/activitypub/models/person.js'; import { createPerson } from '@/remote/activitypub/models/person.js';
import { Resolver } from '@/remote/activitypub/resolver.js'; import { Resolver } from '@/remote/activitypub/resolver.js';
import { HOUR } from '@/const.js';
export type AuthUser = { export type AuthUser = {
user: IRemoteUser; user: IRemoteUser;
@ -12,11 +13,11 @@ export type AuthUser = {
}; };
const publicKeyCache = new Cache<UserPublickey>( const publicKeyCache = new Cache<UserPublickey>(
Infinity, 2 * HOUR,
(keyId) => UserPublickeys.findOneBy({ keyId }).then(x => x ?? undefined), (keyId) => UserPublickeys.findOneBy({ keyId }).then(x => x ?? undefined),
); );
const publicKeyByUserIdCache = new Cache<UserPublickey>( const publicKeyByUserIdCache = new Cache<UserPublickey>(
Infinity, 2 * HOUR,
(userId) => UserPublickeys.findOneBy({ userId }).then(x => x ?? undefined), (userId) => UserPublickeys.findOneBy({ userId }).then(x => x ?? undefined),
); );