|
|
|
|
@ -46,7 +46,7 @@ def _build_card(sqlite_row, redis_state, merged):
|
|
|
|
|
# ============================================================
|
|
|
|
|
# INSPECT ONLY — NO WRITES
|
|
|
|
|
# ============================================================
|
|
|
|
|
def inspect_books_state():
|
|
|
|
|
def inspect_books_state_depecrated():
|
|
|
|
|
"""
|
|
|
|
|
Reads all books from SQLite and fetches Redis progress.
|
|
|
|
|
Builds:
|
|
|
|
|
@ -121,6 +121,88 @@ def inspect_books_state():
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
# INSPECT ONLY — NO WRITES
|
|
|
|
|
# ============================================================
|
|
|
|
|
def inspect_books_state():
|
|
|
|
|
"""
|
|
|
|
|
Reads canonical book state from repository.
|
|
|
|
|
Builds:
|
|
|
|
|
• entry.sqlite
|
|
|
|
|
• entry.redis
|
|
|
|
|
• entry.would_merge_to
|
|
|
|
|
• entry.card (book-card compatible)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from db.repository import get_book_state
|
|
|
|
|
from db.db import get_db
|
|
|
|
|
|
|
|
|
|
db = get_db()
|
|
|
|
|
cur = db.cursor()
|
|
|
|
|
|
|
|
|
|
# Alleen nodig om te weten *welke* books er zijn
|
|
|
|
|
cur.execute("SELECT book_idx FROM books")
|
|
|
|
|
rows = cur.fetchall()
|
|
|
|
|
|
|
|
|
|
results = []
|
|
|
|
|
|
|
|
|
|
for row in rows:
|
|
|
|
|
book_idx = row["book_idx"]
|
|
|
|
|
|
|
|
|
|
# --------------------------------
|
|
|
|
|
# Canonical state (ENIGE waarheid)
|
|
|
|
|
# --------------------------------
|
|
|
|
|
state = get_book_state(book_idx)
|
|
|
|
|
|
|
|
|
|
# SQLite-view = alleen SQLite-kolommen
|
|
|
|
|
sqlite_view = {
|
|
|
|
|
k: v
|
|
|
|
|
for k, v in state.items()
|
|
|
|
|
if k
|
|
|
|
|
in (
|
|
|
|
|
"book_idx",
|
|
|
|
|
"title",
|
|
|
|
|
"author",
|
|
|
|
|
"description",
|
|
|
|
|
"cover_path",
|
|
|
|
|
"book_url",
|
|
|
|
|
"chapters_total",
|
|
|
|
|
"status",
|
|
|
|
|
"downloaded",
|
|
|
|
|
"parsed",
|
|
|
|
|
"audio_done",
|
|
|
|
|
"created_at",
|
|
|
|
|
"processdate",
|
|
|
|
|
"last_update",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Redis-view = alleen Redis counters/status
|
|
|
|
|
redis_view = {
|
|
|
|
|
k: v
|
|
|
|
|
for k, v in state.items()
|
|
|
|
|
if k.startswith("chapters_")
|
|
|
|
|
or k in ("status", "audio_done", "audio_skipped")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
merged = state # letterlijk de canonieke state
|
|
|
|
|
|
|
|
|
|
card = _build_card(sqlite_view, redis_view, merged)
|
|
|
|
|
|
|
|
|
|
results.append(
|
|
|
|
|
{
|
|
|
|
|
"book_idx": book_idx,
|
|
|
|
|
"title": state.get("title"),
|
|
|
|
|
"sqlite": sqlite_view,
|
|
|
|
|
"redis": redis_view,
|
|
|
|
|
"would_merge_to": merged,
|
|
|
|
|
"card": card,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
# SYNC REDIS → SQLITE (writes)
|
|
|
|
|
# ============================================================
|
|
|
|
|
|