mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-25 02:09:05 +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 logger = remoteLogger.createSubLogger("resolve-user");
|
||||||
const uriHostCache = new Cache<string>("resolveUserUriHost", 60 * 60 * 24);
|
const uriHostCache = new Cache<string>("resolveUserUriHost", 60 * 60 * 24);
|
||||||
|
const mentionUriCache = new Cache<string>("resolveMentionUserUri", 60 * 60 * 72);
|
||||||
|
|
||||||
export async function resolveUser(
|
export async function resolveUser(
|
||||||
username: string,
|
username: string,
|
||||||
@ -188,6 +189,7 @@ export async function resolveMentionWithFallback(username: string, host: string
|
|||||||
if (cached) return cached.url ?? cached.uri;
|
if (cached) return cached.url ?? cached.uri;
|
||||||
if ((host === null && objectHost === null) || host === config.domain) return fallback;
|
if ((host === null && objectHost === null) || host === config.domain) return fallback;
|
||||||
|
|
||||||
|
return mentionUriCache.fetch(fallback, async () => {
|
||||||
try {
|
try {
|
||||||
const user = await resolveUser(username, host ?? objectHost, false);
|
const user = await resolveUser(username, host ?? objectHost, false);
|
||||||
const profile = await UserProfiles.findOneBy({ userId: user.id });
|
const profile = await UserProfiles.findOneBy({ userId: user.id });
|
||||||
@ -196,6 +198,7 @@ export async function resolveMentionWithFallback(username: string, host: string
|
|||||||
catch {
|
catch {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSubjectHostFromUri(uri: string): Promise<string | null> {
|
export async function getSubjectHostFromUri(uri: string): Promise<string | null> {
|
||||||
|
Loading…
Reference in New Issue
Block a user