sync errors

This commit is contained in:
2026-05-10 18:02:06 +02:00
parent e754b14085
commit 96e555de0a
5 changed files with 154 additions and 23 deletions
+42 -1
View File
@@ -68,6 +68,12 @@ def init_db() -> None:
status TEXT DEFAULT 'running',
error_msg TEXT
);
CREATE TABLE IF NOT EXISTS remote_zip_cache (
remote_path TEXT PRIMARY KEY,
file_size INTEGER NOT NULL,
cached_at TEXT NOT NULL
);
""")
@@ -110,6 +116,39 @@ def get_all_processed_paths() -> set[str]:
return {row["remote_path"] for row in rows}
# --- Remote zip cache ---
def get_remote_zip_cache() -> list[tuple[str, int]]:
"""Return cached (remote_path, file_size) tuples."""
with get_db() as conn:
rows = conn.execute("SELECT remote_path, file_size FROM remote_zip_cache").fetchall()
return [(row["remote_path"], row["file_size"]) for row in rows]
def upsert_remote_zip_cache(zips: list[tuple[str, int]]) -> None:
"""Bulk-insert or replace cache entries. zips is a list of (remote_path, file_size)."""
now = _now()
with get_db() as conn:
conn.executemany(
"INSERT INTO remote_zip_cache (remote_path, file_size, cached_at) VALUES (?,?,?)"
" ON CONFLICT(remote_path) DO UPDATE SET file_size=excluded.file_size, cached_at=excluded.cached_at",
[(path, size, now) for path, size in zips],
)
def get_remote_cache_info() -> dict:
with get_db() as conn:
row = conn.execute(
"SELECT COUNT(*) as count, MAX(cached_at) as last_scan FROM remote_zip_cache"
).fetchone()
return {"count": row["count"], "last_scan": row["last_scan"]}
def clear_remote_zip_cache() -> int:
with get_db() as conn:
return conn.execute("DELETE FROM remote_zip_cache").rowcount
def mark_zip_processed(remote_path: str, file_size: int, status: str, error_msg: str | None = None) -> None:
with get_db() as conn:
conn.execute(
@@ -212,11 +251,13 @@ def get_stats() -> dict:
def clear_sync_data() -> dict:
"""Delete all processed_zips, uploaded_books, and sync_runs rows. Settings are kept."""
"""Delete all processed_zips, uploaded_books, and sync_runs rows. Settings are kept.
Also resets the remote scan timestamp so the next sync does a full rescan."""
with get_db() as conn:
zips = conn.execute("DELETE FROM processed_zips").rowcount
books = conn.execute("DELETE FROM uploaded_books").rowcount
runs = conn.execute("DELETE FROM sync_runs").rowcount
conn.execute("DELETE FROM settings WHERE key = 'remote_cache_last_scan'")
return {"zips": zips, "books": books, "runs": runs}