feat: better cache stats

This commit is contained in:
2026-04-02 10:48:26 +02:00
parent 7aba5c854e
commit eefda2140e
4 changed files with 85 additions and 10 deletions
+43
View File
@@ -441,10 +441,53 @@ class CacheEngine:
"SELECT source, COUNT(*) FROM cache GROUP BY source"
).fetchall()
)
# Source × Status cross-tabulation
source_status = conn.execute(
"SELECT source, status, COUNT(*) FROM cache GROUP BY source, status"
).fetchall()
# Confidence buckets (only for positive statuses)
confidence_rows = conn.execute(
"SELECT confidence FROM cache WHERE status IN (?, ?)",
(
CacheStatus.SUCCESS_SYNCED.value,
CacheStatus.SUCCESS_UNSYNCED.value,
),
).fetchall()
# Build source×status table: {source: {status: count}}
source_status_table: dict[str, dict[str, int]] = {}
for src, status, count in source_status:
source_status_table.setdefault(src, {})[status] = count
# Build confidence buckets
buckets = {
"legacy (NULL)": 0,
"0-24": 0,
"25-49": 0,
"50-79": 0,
"80-99": 0,
"100": 0,
}
for (conf,) in confidence_rows:
if conf is None:
buckets["legacy (NULL)"] += 1
elif conf >= 100:
buckets["100"] += 1
elif conf >= 80:
buckets["80-99"] += 1
elif conf >= 50:
buckets["50-79"] += 1
elif conf >= 25:
buckets["25-49"] += 1
else:
buckets["0-24"] += 1
return {
"total": total,
"expired": expired,
"active": total - expired,
"by_status": by_status,
"by_source": by_source,
"source_status": source_status_table,
"confidence_buckets": buckets,
}