From 57299f0df6f03d5892a4a7795b26b478f460270e Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sun, 13 Nov 2022 17:14:33 +0100 Subject: [PATCH] server: simplify caching for instance actor --- .../backend/src/services/instance-actor.ts | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/services/instance-actor.ts b/packages/backend/src/services/instance-actor.ts index 6d46fc24c..874952be0 100644 --- a/packages/backend/src/services/instance-actor.ts +++ b/packages/backend/src/services/instance-actor.ts @@ -1,28 +1,20 @@ import { IsNull } from 'typeorm'; import { ILocalUser } from '@/models/entities/user.js'; import { Users } from '@/models/index.js'; -import { Cache } from '@/misc/cache.js'; import { createSystemUser } from './create-system-user.js'; const ACTOR_USERNAME = 'instance.actor' as const; -const cache = new Cache(Infinity); +let instanceActor = await Users.findOneBy({ + host: IsNull(), + username: ACTOR_USERNAME, +}) as ILocalUser | undefined; export async function getInstanceActor(): Promise { - const cached = cache.get(null); - if (cached) return cached; - - const user = await Users.findOneBy({ - host: IsNull(), - username: ACTOR_USERNAME, - }) as ILocalUser | undefined; - - if (user) { - cache.set(null, user); - return user; + if (instanceActor) { + return instanceActor; } else { - const created = await createSystemUser(ACTOR_USERNAME) as ILocalUser; - cache.set(null, created); + instanceActor = await createSystemUser(ACTOR_USERNAME) as ILocalUser; return created; } }