mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-25 13:39:06 +01:00
[backend] Cache mention uri in resolveMentionWithFallback
This commit is contained in:
parent
c0d7ecf5c3
commit
fe165dd4d3
@ -13,6 +13,7 @@ import { IMentionedRemoteUsers } from "@/models/entities/note.js";
|
||||
|
||||
const logger = remoteLogger.createSubLogger("resolve-user");
|
||||
const uriHostCache = new Cache<string>("resolveUserUriHost", 60 * 60 * 24);
|
||||
const mentionUriCache = new Cache<string>("resolveMentionUserUri", 60 * 60 * 72);
|
||||
|
||||
export async function resolveUser(
|
||||
username: string,
|
||||
@ -188,14 +189,16 @@ export async function resolveMentionWithFallback(username: string, host: string
|
||||
if (cached) return cached.url ?? cached.uri;
|
||||
if ((host === null && objectHost === null) || host === config.domain) return fallback;
|
||||
|
||||
try {
|
||||
const user = await resolveUser(username, host ?? objectHost, false);
|
||||
const profile = await UserProfiles.findOneBy({ userId: user.id });
|
||||
return profile?.url ?? user.uri ?? fallback;
|
||||
}
|
||||
catch {
|
||||
return fallback;
|
||||
}
|
||||
return mentionUriCache.fetch(fallback, async () => {
|
||||
try {
|
||||
const user = await resolveUser(username, host ?? objectHost, false);
|
||||
const profile = await UserProfiles.findOneBy({ userId: user.id });
|
||||
return profile?.url ?? user.uri ?? fallback;
|
||||
}
|
||||
catch {
|
||||
return fallback;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function getSubjectHostFromUri(uri: string): Promise<string | null> {
|
||||
|
Loading…
Reference in New Issue
Block a user