Fix recovery stale-URL handling and task accounting
This commit is contained in:
@@ -709,7 +709,8 @@ export class ScrapeEngine {
|
||||
// resolve one from the provider or the page before caching it.
|
||||
let previewRow = row;
|
||||
if (row.source === "embed" && !row.preview_url) {
|
||||
const resolved = await resolveEmbedPreview(row, options);
|
||||
// play_url is the refreshed direct media link; url may carry an expired signature.
|
||||
const resolved = await resolveEmbedPreview({ ...row, url: row.play_url ?? row.url }, options);
|
||||
if (!resolved) {
|
||||
store.markPreviewError(row.id, "no preview source");
|
||||
result.skipped++;
|
||||
@@ -812,7 +813,12 @@ export class ScrapeEngine {
|
||||
playUrl: row.play_url
|
||||
});
|
||||
if (refreshed && refreshed !== previewRow.url) {
|
||||
const retry = await downloadPreview({ ...previewRow, url: refreshed }, join(dir, "thumbs"), options);
|
||||
let retryRow = { ...previewRow, url: refreshed };
|
||||
if (row.source === "embed") {
|
||||
const again = await resolveEmbedPreview({ ...row, url: refreshed }, options);
|
||||
if (again) retryRow = { ...retryRow, preview_url: again };
|
||||
}
|
||||
const retry = await downloadPreview(retryRow, join(dir, "thumbs"), options);
|
||||
if (retry.state === "downloaded" && retry.hash) {
|
||||
store.markPreview(row.id, {
|
||||
hash: retry.hash,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user