Mark recovery-exhausted rows unavailable

This commit is contained in:
Fisto
2026-09-18 12:54:11 +02:00
parent faacedd8f5
commit 46e4fc23c0
2 changed files with 22 additions and 5 deletions
+14 -2
View File
@@ -582,7 +582,8 @@ export class ScrapeStore {
`SELECT * FROM media `SELECT * FROM media
WHERE preview_hash IS NULL WHERE preview_hash IS NULL
AND lower(COALESCE(url, '') || ' ' || COALESCE(play_url, '')) LIKE '%discordapp%' AND lower(COALESCE(url, '') || ' ' || COALESCE(play_url, '')) LIKE '%discordapp%'
AND (preview_error IS NOT NULL AND ((preview_error IS NOT NULL
AND preview_error NOT LIKE 'unavailable after recovery%')
OR (preview_suspect IS NOT NULL OR (preview_suspect IS NOT NULL
AND (preview_retry_at IS NULL OR preview_retry_at <= ?))) AND (preview_retry_at IS NULL OR preview_retry_at <= ?)))
ORDER BY id LIMIT ?` ORDER BY id LIMIT ?`
@@ -594,13 +595,24 @@ export class ScrapeStore {
this.db.prepare("UPDATE media SET preview_error = NULL WHERE id = ?").run(id); this.db.prepare("UPDATE media SET preview_error = NULL WHERE id = ?").run(id);
} }
/** The recovery task refreshed and retried this row; it is genuinely unavailable now. */
markUnavailableAfterRecovery(id: number): void {
this.db
.prepare(
"UPDATE media SET preview_error = 'unavailable after recovery', preview_suspect = NULL, preview_retry_at = NULL WHERE id = ?"
)
.run(id);
}
discordPreviewFailureCount(): number { discordPreviewFailureCount(): number {
const row = this.db const row = this.db
.prepare( .prepare(
`SELECT COUNT(*) AS count FROM media `SELECT COUNT(*) AS count FROM media
WHERE preview_hash IS NULL WHERE preview_hash IS NULL
AND lower(COALESCE(url, '') || ' ' || COALESCE(play_url, '')) LIKE '%discordapp%' AND lower(COALESCE(url, '') || ' ' || COALESCE(play_url, '')) LIKE '%discordapp%'
AND (preview_error IS NOT NULL OR preview_suspect IS NOT NULL)` AND ((preview_error IS NOT NULL
AND preview_error NOT LIKE 'unavailable after recovery%')
OR preview_suspect IS NOT NULL)`
) )
.get() as { count: number | null } | undefined; .get() as { count: number | null } | undefined;
return row?.count ?? 0; return row?.count ?? 0;
+8 -3
View File
@@ -453,9 +453,14 @@ export class MediaService {
await this.engine.previewBatch(scrapeId, cleared.length); await this.engine.previewBatch(scrapeId, cleared.length);
for (const row of cleared) { for (const row of cleared) {
const after = store.getMedia(row.id); const after = store.getMedia(row.id);
if (after?.preview_hash) this.recover.recovered++; if (after?.preview_hash) {
else if (after?.preview_suspect) this.recover.deferred++; this.recover.recovered++;
else this.recover.gone++; } else {
// Refreshed URL plus a fetch still failed: the file is gone. Mark it
// so later recovery runs do not retry it again.
if (after?.preview_suspect) store.markUnavailableAfterRecovery(row.id);
this.recover.gone++;
}
} }
} }
} finally { } finally {