From 1d543b5bf87139e7638a741c31e4f602ad4acfc6 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 11 Sep 2023 22:15:48 +0200 Subject: [PATCH] Cache resolved split domain mentions --- packages/backend/src/remote/resolve-user.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index a75c810df..22d7cb462 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -8,8 +8,10 @@ import { toPuny } from "@/misc/convert-host.js"; import webFinger from "./webfinger.js"; import { createPerson, updatePerson } from "./activitypub/models/person.js"; import { remoteLogger } from "./logger.js"; +import { Cache } from "@/misc/cache.js"; const logger = remoteLogger.createSubLogger("resolve-user"); +const uriHostCache = new Cache("resolveUserUriHost", 60 * 60 * 24); export async function resolveUser( username: string, @@ -200,7 +202,7 @@ export async function getSubjectHostFromUriAndUsernameCached(uri: string, userna return user.host; } - return await getSubjectHostFromUri(uri) ?? hostname; + return await uriHostCache.fetch(uri, async () => await getSubjectHostFromUri(uri) ?? hostname); } export async function getSubjectHostFromAcct(acct: string): Promise {