Sweep due suspects and count them in recovery

This commit is contained in:
Fisto
2026-09-18 12:04:41 +02:00
parent e3edd9c200
commit faacedd8f5
2 changed files with 28 additions and 6 deletions
+5 -5
View File
@@ -576,17 +576,18 @@ export class ScrapeStore {
* 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[] {
discordPreviewFailures(limit = 5000, nowMs = Date.now()): MediaRow[] {
return this.db
.prepare(
`SELECT * 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))
OR (preview_suspect IS NOT NULL
AND (preview_retry_at IS NULL OR preview_retry_at <= ?)))
ORDER BY id LIMIT ?`
)
.all(limit) as unknown as MediaRow[];
.all(nowMs, limit) as unknown as MediaRow[];
}
clearPreviewError(id: number): void {
@@ -599,8 +600,7 @@ export class ScrapeStore {
`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))`
AND (preview_error IS NOT NULL OR preview_suspect IS NOT NULL)`
)
.get() as { count: number | null } | undefined;
return row?.count ?? 0;