diff --git a/src/routers/sources.py b/src/routers/sources.py index ef3522c..7a3f8d7 100644 --- a/src/routers/sources.py +++ b/src/routers/sources.py @@ -594,14 +594,25 @@ async def get_health( "limit": limit, "offset": offset, "has_more": False, } - # Aggregate über GESAMTEN Bestand (eine GROUP-BY-Query, billig) + # Aggregate über GESAMTEN Bestand. Eine GROUP-BY-Query nach (check_type, status) + # liefert sowohl die Top-Counters als auch das feine Breakdown für die UI. cursor = await db.execute( - "SELECT status, COUNT(*) AS n FROM source_health_checks GROUP BY status" + "SELECT check_type, status, COUNT(*) AS n FROM source_health_checks GROUP BY check_type, status" ) - counts = {row["status"]: row["n"] for row in await cursor.fetchall()} - error_count = counts.get("error", 0) - warning_count = counts.get("warning", 0) - ok_count = counts.get("ok", 0) + breakdown = {} # {check_type: {status: count}} + error_count = 0 + warning_count = 0 + ok_count = 0 + for row in await cursor.fetchall(): + ct = row["check_type"] + st = row["status"] + breakdown.setdefault(ct, {})[st] = row["n"] + if st == "error": + error_count += row["n"] + elif st == "warning": + warning_count += row["n"] + elif st == "ok": + ok_count += row["n"] total_checks = error_count + warning_count + ok_count # Paginierte Daten @@ -641,6 +652,7 @@ async def get_health( "errors": error_count, "warnings": warning_count, "ok": ok_count, + "breakdown": breakdown, "checks": checks, "all_orgs": all_orgs, "limit": limit, diff --git a/src/static/dashboard.html b/src/static/dashboard.html index 02fc726..421014e 100644 --- a/src/static/dashboard.html +++ b/src/static/dashboard.html @@ -715,7 +715,7 @@ - +