fix(cache): ensure pasteExpiresAt is valid before cache deletion

This commit is contained in:
2026-03-26 17:52:38 -04:00
parent 5296efa9db
commit c98aca92b6
+6 -2
View File
@@ -125,7 +125,11 @@ export async function getCachedOgImage(id: string): Promise<CachedOgImage | null
return null; return null;
} }
if (typeof row.pasteExpiresAt === 'number' && row.pasteExpiresAt <= Date.now()) { if (
typeof row.pasteExpiresAt === 'number' &&
row.pasteExpiresAt > 0 &&
row.pasteExpiresAt <= Date.now()
) {
await deleteCacheEntry(id, row.relativePath); await deleteCacheEntry(id, row.relativePath);
return null; return null;
} }
@@ -175,7 +179,7 @@ async function purgeExpiredCache(limit: number = PURGE_BATCH_SIZE): Promise<void
`SELECT paste_id AS pasteId, relative_path AS relativePath `SELECT paste_id AS pasteId, relative_path AS relativePath
FROM og_image_cache FROM og_image_cache
WHERE cache_expires_at <= ? WHERE cache_expires_at <= ?
OR (paste_expires_at IS NOT NULL AND paste_expires_at <= ?) OR (paste_expires_at IS NOT NULL AND paste_expires_at > 0 AND paste_expires_at <= ?)
LIMIT ?` LIMIT ?`
) )
.all(now, now, limit) as ExpiredCacheRow[]; .all(now, now, limit) as ExpiredCacheRow[];