feat: show tag counts alongside doc counts on dashboard
All checks were successful
Deploy / deploy (push) Successful in 21s

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 <noreply@anthropic.com>
This commit is contained in:
2026-03-26 21:18:24 +01:00
parent 874f1dce0d
commit 12e0e7d202
2 changed files with 13 additions and 6 deletions

View File

@@ -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:

View File

@@ -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"<span><strong>{label}:</strong> {val} docs</span>")
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"<span><strong>{label}:</strong> {doc_val} docs, {tag_val} tags</span>")
html = (
'<div style="display:flex; gap:1.5rem; flex-wrap:wrap; margin-bottom:1rem; font-size:0.95em;">'