From 12e0e7d2029e4d7da097d521430e92e8551f5773 Mon Sep 17 00:00:00 2001 From: domverse Date: Thu, 26 Mar 2026 21:18:24 +0100 Subject: [PATCH] feat: show tag counts alongside doc counts on dashboard Fetch /api/tags/ in parallel with /api/documents/ for each instance. Dashboard now displays "X docs, Y tags" per master/replica. Co-Authored-By: Claude Sonnet 4.6 --- app/api/status.py | 4 ++-- app/ui/routes.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/api/status.py b/app/api/status.py index d291927..d30b1bc 100644 --- a/app/api/status.py +++ b/app/api/status.py @@ -89,13 +89,13 @@ def get_status(session: Session = Depends(get_session)): } -async def _fetch_count(url: str, token: str) -> int | None: +async def _fetch_count(url: str, token: str, path: str = "/api/documents/") -> int | None: import httpx try: async with httpx.AsyncClient( headers={"Authorization": f"Token {token}"}, timeout=8.0 ) as client: - r = await client.get(url.rstrip("/") + "/api/documents/", params={"page_size": 1}) + r = await client.get(url.rstrip("/") + path, params={"page_size": 1}) r.raise_for_status() return r.json().get("count") except Exception: diff --git a/app/ui/routes.py b/app/ui/routes.py index ce8d4f0..3ac192e 100644 --- a/app/ui/routes.py +++ b/app/ui/routes.py @@ -70,12 +70,19 @@ async def doc_counts_fragment(request: Request, session: Session = Depends(get_s token = decrypt(r.api_token, config.secret_key) tasks.append((r.name, r.url, token)) - counts_raw = await asyncio.gather(*[_fetch_count(url, tok) for _, url, tok in tasks]) + n = len(tasks) + all_counts = await asyncio.gather( + *[_fetch_count(url, tok) for _, url, tok in tasks], + *[_fetch_count(url, tok, "/api/tags/") for _, url, tok in tasks], + ) + doc_counts = all_counts[:n] + tag_counts = all_counts[n:] parts = [] - for (label, _, _), count in zip(tasks, counts_raw): - val = str(count) if count is not None else "?" - parts.append(f"{label}: {val} docs") + for (label, _, _), docs, tags in zip(tasks, doc_counts, tag_counts): + doc_val = str(docs) if docs is not None else "?" + tag_val = str(tags) if tags is not None else "?" + parts.append(f"{label}: {doc_val} docs, {tag_val} tags") html = ( '
'