Fix recovery stale-URL handling and task accounting

This commit is contained in:
Fisto
2026-09-18 11:59:41 +02:00
parent 2ae90b23f4
commit e3edd9c200
6 changed files with 67 additions and 13 deletions
+13 -4
View File
@@ -572,13 +572,18 @@ export class ScrapeStore {
this.db.prepare("UPDATE media SET preview_suspect = NULL, preview_retry_at = NULL WHERE id = ?").run(id);
}
/** Discord-CDN rows closed out with an HTTP error; the recovery task retries these. */
/**
* Discord-CDN rows the recovery task retries: closed out with an HTTP error, or suspect rows
* whose single retry already failed (they may have been hit by the same stale-URL bug).
*/
discordPreviewFailures(limit = 5000): MediaRow[] {
return this.db
.prepare(
`SELECT * FROM media
WHERE preview_hash IS NULL AND preview_error IS NOT NULL
AND lower(url) LIKE '%discordapp%'
WHERE preview_hash IS NULL
AND lower(COALESCE(url, '') || ' ' || COALESCE(play_url, '')) LIKE '%discordapp%'
AND (preview_error IS NOT NULL
OR (preview_suspect IS NOT NULL AND preview_retry_at IS NULL))
ORDER BY id LIMIT ?`
)
.all(limit) as unknown as MediaRow[];
@@ -591,7 +596,11 @@ export class ScrapeStore {
discordPreviewFailureCount(): number {
const row = this.db
.prepare(
"SELECT COUNT(*) AS count FROM media WHERE preview_hash IS NULL AND preview_error IS NOT NULL AND lower(url) LIKE '%discordapp%'"
`SELECT COUNT(*) AS count FROM media
WHERE preview_hash IS NULL
AND lower(COALESCE(url, '') || ' ' || COALESCE(play_url, '')) LIKE '%discordapp%'
AND (preview_error IS NOT NULL
OR (preview_suspect IS NOT NULL AND preview_retry_at IS NULL))`
)
.get() as { count: number | null } | undefined;
return row?.count ?? 0;