mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-21 17:37:29 -07:00
[backend/masto-client] Fix user profile html cache not updating
This commit is contained in:
parent
562b378b1b
commit
dcfa69ff9d
1 changed files with 8 additions and 8 deletions
|
@ -35,7 +35,7 @@ export class UserConverter {
|
|||
const cacheHit = cache.accounts.find(p => p.id == u.id);
|
||||
if (cacheHit) return cacheHit;
|
||||
|
||||
const identifier = `${u.id}:${(u.lastFetchedAt ?? u.createdAt).getTime()}`;
|
||||
const identifier = `${u.id}:${(u.lastFetchedAt ?? u.updatedAt ?? u.createdAt).getTime()}`;
|
||||
let fqn = `${u.username}@${u.host ?? config.domain}`;
|
||||
let acct = u.username;
|
||||
let acctUrl = `https://${u.host || config.host}/@${u.username}`;
|
||||
|
@ -243,7 +243,7 @@ export class UserConverter {
|
|||
|
||||
return Promise.resolve(dbHit)
|
||||
.then(res => {
|
||||
if (res === null || (res.updatedAt.getTime() !== (user.lastFetchedAt ?? user.createdAt).getTime())) {
|
||||
if (res === null || (res.updatedAt.getTime() !== (user.lastFetchedAt ?? user.updatedAt ?? user.createdAt).getTime())) {
|
||||
return this.dbCacheMiss(user, profile, ctx);
|
||||
}
|
||||
return res;
|
||||
|
@ -251,7 +251,7 @@ export class UserConverter {
|
|||
}
|
||||
|
||||
private static async dbCacheMiss(user: User, profile: UserProfile | null, ctx: MastoContext): Promise<HtmlUserCacheEntry | null> {
|
||||
const identifier = `${user.id}:${(user.lastFetchedAt ?? user.createdAt).getTime()}`;
|
||||
const identifier = `${user.id}:${(user.lastFetchedAt ?? user.updatedAt ?? user.createdAt).getTime()}`;
|
||||
const cache = ctx.cache as AccountCache;
|
||||
return cache.locks.acquire(identifier, async () => {
|
||||
const cachedBio = await this.userBioHtmlCache.get(identifier);
|
||||
|
@ -277,7 +277,7 @@ export class UserConverter {
|
|||
fields = Promise.all(profile!.fields.map(async p => this.encodeField(p, user.host, profile!.mentions)) ?? []);
|
||||
}
|
||||
|
||||
HtmlUserCacheEntries.upsert({ userId: user.id, updatedAt: user.lastFetchedAt ?? user.createdAt, bio: await bio, fields: await fields }, ["userId"]);
|
||||
HtmlUserCacheEntries.upsert({ userId: user.id, updatedAt: user.lastFetchedAt ?? user.updatedAt ?? user.createdAt, bio: await bio, fields: await fields }, ["userId"]);
|
||||
|
||||
await this.userBioHtmlCache.set(identifier, await bio);
|
||||
await this.userFieldsHtmlCache.set(identifier, await fields);
|
||||
|
@ -287,14 +287,14 @@ export class UserConverter {
|
|||
}
|
||||
|
||||
public static async prewarmCache(user: User, profile?: UserProfile | null, oldProfile?: UserProfile | null): Promise<void> {
|
||||
const identifier = `${user.id}:${(user.lastFetchedAt ?? user.createdAt).getTime()}`;
|
||||
const identifier = `${user.id}:${(user.lastFetchedAt ?? user.updatedAt ?? user.createdAt).getTime()}`;
|
||||
if (profile !== null) {
|
||||
if (config.htmlCache?.dbFallback) {
|
||||
if (profile === undefined) {
|
||||
profile = await UserProfiles.findOneBy({ userId: user.id });
|
||||
}
|
||||
if (oldProfile !== undefined && profile?.fields === oldProfile?.fields && profile?.description === oldProfile?.description) {
|
||||
HtmlUserCacheEntries.update({ userId: user.id }, { updatedAt: user.lastFetchedAt ?? user.createdAt });
|
||||
HtmlUserCacheEntries.update({ userId: user.id }, { updatedAt: user.lastFetchedAt ?? user.updatedAt ?? user.createdAt });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ export class UserConverter {
|
|||
this.userBioHtmlCache.set(identifier, await bio);
|
||||
|
||||
if (config.htmlCache?.dbFallback)
|
||||
HtmlUserCacheEntries.upsert({ userId: user.id, updatedAt: user.lastFetchedAt ?? user.createdAt, bio: await bio }, ["userId"]);
|
||||
HtmlUserCacheEntries.upsert({ userId: user.id, updatedAt: user.lastFetchedAt ?? user.updatedAt ?? user.createdAt, bio: await bio }, ["userId"]);
|
||||
}
|
||||
|
||||
if (await this.userFieldsHtmlCache.get(identifier) === undefined) {
|
||||
|
@ -321,7 +321,7 @@ export class UserConverter {
|
|||
this.userFieldsHtmlCache.set(identifier, fields);
|
||||
|
||||
if (config.htmlCache?.dbFallback)
|
||||
HtmlUserCacheEntries.upsert({ userId: user.id, updatedAt: user.lastFetchedAt ?? user.createdAt, fields: fields }, ["userId"]);
|
||||
HtmlUserCacheEntries.upsert({ userId: user.id, updatedAt: user.lastFetchedAt ?? user.updatedAt ?? user.createdAt, fields: fields }, ["userId"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue