mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2025-01-10 15:40:57 -07:00
[backend] Don't refresh user data in resolveMentionWithFallback
This commit is contained in:
parent
ce29c1dce2
commit
588a39f17a
1 changed files with 6 additions and 3 deletions
|
@ -17,6 +17,7 @@ const uriHostCache = new Cache<string>("resolveUserUriHost", 60 * 60 * 24);
|
||||||
export async function resolveUser(
|
export async function resolveUser(
|
||||||
username: string,
|
username: string,
|
||||||
host: string | null,
|
host: string | null,
|
||||||
|
refresh: boolean = true
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
const usernameLower = username.toLowerCase();
|
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 information is out of date, return it by starting over from WebFilger
|
||||||
if (
|
if (
|
||||||
user.lastFetchedAt == null ||
|
refresh && (
|
||||||
Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24
|
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
|
// Prevent multiple attempts to connect to unconnected instances, update before each attempt to prevent subsequent similar attempts
|
||||||
await Users.update(user.id, {
|
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 (cached) return cached.url ?? cached.uri;
|
||||||
if (host === null || host === config.domain) return fallback;
|
if (host === null || host === config.domain) return fallback;
|
||||||
try {
|
try {
|
||||||
const user = await resolveUser(username, host);
|
const user = await resolveUser(username, host, false);
|
||||||
const profile = await UserProfiles.findOneBy({ userId: user.id });
|
const profile = await UserProfiles.findOneBy({ userId: user.id });
|
||||||
return profile?.url ?? user.uri ?? fallback;
|
return profile?.url ?? user.uri ?? fallback;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue