mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
cache alternate URLs in UrlPreviewService
This commit is contained in:
parent
865b198ab3
commit
a91c0de9b5
1 changed files with 17 additions and 1 deletions
|
@ -185,7 +185,7 @@ export class UrlPreviewService {
|
|||
return;
|
||||
}
|
||||
|
||||
const cacheKey = `${url}@${lang}@${cacheFormatVersion}`;
|
||||
const cacheKey = getCacheKey(url, lang);
|
||||
if (await this.sendCachedPreview(cacheKey, reply, fetch)) {
|
||||
return;
|
||||
}
|
||||
|
@ -236,6 +236,18 @@ export class UrlPreviewService {
|
|||
// Await this to avoid hammering redis when a bunch of URLs are fetched at once
|
||||
await this.previewCache.set(cacheKey, summary);
|
||||
|
||||
// Also cache the response URL in case of redirects
|
||||
if (summary.url !== url) {
|
||||
const responseCacheKey = getCacheKey(summary.url, lang);
|
||||
await this.previewCache.set(responseCacheKey, summary);
|
||||
}
|
||||
|
||||
// Also cache the ActivityPub URL, if different from the others
|
||||
if (summary.activityPub && summary.activityPub !== summary.url) {
|
||||
const apCacheKey = getCacheKey(summary.activityPub, lang);
|
||||
await this.previewCache.set(apCacheKey, summary);
|
||||
}
|
||||
|
||||
// Cache 1 day (matching redis), but only once we finalize the result
|
||||
if (!summary.activityPub || summary.haveNoteLocally) {
|
||||
reply.header('Cache-Control', 'public, max-age=86400');
|
||||
|
@ -552,3 +564,7 @@ export class UrlPreviewService {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function getCacheKey(url: string, lang = 'none') {
|
||||
return `${url}@${lang}@${cacheFormatVersion}`;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue