From 588a39f17a859654c45e77fb2d784fe1d1db1c4f Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 14 Oct 2023 16:57:04 +0200 Subject: [PATCH] [backend] Don't refresh user data in resolveMentionWithFallback --- packages/backend/src/remote/resolve-user.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index 7855c4372..e97ea3ab6 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -17,6 +17,7 @@ const uriHostCache = new Cache("resolveUserUriHost", 60 * 60 * 24); export async function resolveUser( username: string, host: string | null, + refresh: boolean = true ): Promise { const usernameLower = username.toLowerCase(); @@ -102,8 +103,10 @@ export async function resolveUser( // If user information is out of date, return it by starting over from WebFilger if ( - user.lastFetchedAt == null || - Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24 + refresh && ( + user.lastFetchedAt == null || + Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24 + ) ) { // Prevent multiple attempts to connect to unconnected instances, update before each attempt to prevent subsequent similar attempts await Users.update(user.id, { @@ -180,7 +183,7 @@ export async function resolveMentionWithFallback(username: string, host: string if (cached) return cached.url ?? cached.uri; if (host === null || host === config.domain) return fallback; try { - const user = await resolveUser(username, host); + const user = await resolveUser(username, host, false); const profile = await UserProfiles.findOneBy({ userId: user.id }); return profile?.url ?? user.uri ?? fallback; }