Fix false "Plex fallback" banner during the first scan
history_coverage is only written at the end of an ingest, but has_completion_data was reading from it. During the first scan the coverage table is empty while watch_event already holds tens of thousands of Tautulli rows, so the dashboard announced a fallback that had not happened and claimed the rejection component was disabled when it was not. The flag now comes from the events themselves — does any row carry a percent_complete — which is true the moment Tautulli rows land and false for Plex-only history. history_source falls back to the scan record when coverage is absent, so it reads "tautulli" mid-scan instead of null. Also: the banner named Plex as the source without checking, and now reports whichever source is actually active, and stays quiet while a scan is running since the counts are still moving. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbG48GAXfCZatcmX123Ra
This commit is contained in:
parent
a842aeb344
commit
71cfa31f09
4 changed files with 55 additions and 10 deletions
|
|
@ -34,11 +34,26 @@ def _score_ctx(db, cfg, has_completion_data: bool) -> scoring.ScoreContext:
|
|||
|
||||
|
||||
def history_has_completion(db) -> bool:
|
||||
"""True when the active history source records percent_complete (§4.11)."""
|
||||
row = db.one(
|
||||
"SELECT source FROM history_coverage ORDER BY event_count DESC LIMIT 1"
|
||||
)
|
||||
return bool(row and row["source"] == "tautulli")
|
||||
"""True when the ingested history actually carries percent_complete (§4.11).
|
||||
|
||||
Read from the events themselves, not from history_coverage: that row is only
|
||||
written at the END of an ingest, so during the first scan the coverage table
|
||||
is empty while watch_event is already full of Tautulli rows. Deriving the
|
||||
flag from the table made the UI announce a Plex fallback that had not
|
||||
happened, mid-scan, on every fresh database.
|
||||
"""
|
||||
return bool(db.scalar(
|
||||
"SELECT 1 FROM watch_event WHERE percent_complete IS NOT NULL LIMIT 1"))
|
||||
|
||||
|
||||
def active_history_source(db) -> str | None:
|
||||
"""Which source history came from — coverage if it exists, else the scan."""
|
||||
row = db.one("SELECT source FROM history_coverage ORDER BY event_count DESC LIMIT 1")
|
||||
if row:
|
||||
return row["source"]
|
||||
row = db.one("SELECT history_source FROM scan WHERE history_source IS NOT NULL "
|
||||
"ORDER BY id DESC LIMIT 1")
|
||||
return row["history_source"] if row else None
|
||||
|
||||
|
||||
BASE_COLUMNS = """
|
||||
|
|
@ -273,7 +288,7 @@ def overview(db, cfg) -> dict:
|
|||
"episodes": s("SELECT COUNT(*) FROM episode WHERE status='present'"),
|
||||
"watch_events": s("SELECT COUNT(*) FROM watch_event"),
|
||||
"accounts": s("SELECT COUNT(*) FROM account"),
|
||||
"history_source": cov["source"] if cov else None,
|
||||
"history_source": active_history_source(db),
|
||||
"history_since": cov["earliest_event_at"] if cov else None,
|
||||
"history_until": cov["latest_event_at"] if cov else None,
|
||||
"has_completion_data": history_has_completion(db),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue