Cap transient preview retries and close dead hosts

This commit is contained in:
Fisto
2026-09-17 08:44:55 +02:00
parent 445c6ca2fb
commit e52623f1b2
6 changed files with 104 additions and 7 deletions
+15
View File
@@ -145,6 +145,7 @@ export interface MediaRow {
file_path: string | null;
download_error: string | null;
preview_error: string | null;
preview_attempts: number;
created_at: string;
}
@@ -184,6 +185,7 @@ CREATE TABLE IF NOT EXISTS media (
file_path TEXT,
download_error TEXT,
preview_error TEXT,
preview_attempts INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL
);
@@ -226,6 +228,9 @@ export class ScrapeStore {
if (!names.has("anim_hash")) this.db.exec("ALTER TABLE media ADD COLUMN anim_hash TEXT");
if (!names.has("play_url")) this.db.exec("ALTER TABLE media ADD COLUMN play_url TEXT");
if (!names.has("aspect_ratio")) this.db.exec("ALTER TABLE media ADD COLUMN aspect_ratio REAL");
if (!names.has("preview_attempts")) {
this.db.exec("ALTER TABLE media ADD COLUMN preview_attempts INTEGER NOT NULL DEFAULT 0");
}
}
close(): void {
@@ -379,6 +384,16 @@ export class ScrapeStore {
.run(preview.hash, preview.bytes, preview.ext ?? "webp", id);
}
/** Count one transient preview failure and return the new total. */
bumpPreviewAttempt(id: number): number {
this.db.prepare("UPDATE media SET preview_attempts = preview_attempts + 1 WHERE id = ?").run(id);
const row = this.db.prepare("SELECT preview_attempts FROM media WHERE id = ?").get(id) as
| { preview_attempts: number | null }
| undefined;
return row?.preview_attempts ?? 0;
}
markPreviewError(id: number, error: string): void {
this.db.prepare("UPDATE media SET preview_error = ? WHERE id = ?").run(error.slice(0, 200), id);
}