fix: resync clears last_sync_ts; add live doc counts to dashboard
All checks were successful
Deploy / deploy (push) Successful in 14s
All checks were successful
Deploy / deploy (push) Successful in 14s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,51 @@ def _lag_str(ts: datetime | None) -> str:
|
||||
return f"{seconds // 86400}d ago"
|
||||
|
||||
|
||||
@router.get("/ui/doc-counts", response_class=HTMLResponse)
|
||||
async def doc_counts_fragment(request: Request, session: Session = Depends(get_session)):
|
||||
from .. import envfile
|
||||
from ..api.status import _fetch_count, doc_counts as _doc_counts
|
||||
from ..config import get_config
|
||||
from ..crypto import decrypt
|
||||
from ..models import Setting
|
||||
from ..scheduler import SETTINGS_DEFAULTS
|
||||
import asyncio
|
||||
|
||||
config = get_config()
|
||||
rows = session.exec(select(Setting)).all()
|
||||
settings = dict(SETTINGS_DEFAULTS)
|
||||
for row in rows:
|
||||
if row.value is not None:
|
||||
settings[row.key] = row.value
|
||||
|
||||
master_url = settings.get("master_url", "")
|
||||
master_token_enc = settings.get("master_token", "")
|
||||
master_token = decrypt(master_token_enc, config.secret_key) if master_token_enc else ""
|
||||
|
||||
replicas = session.exec(select(Replica)).all()
|
||||
|
||||
tasks = []
|
||||
if master_url and master_token:
|
||||
tasks.append(("Master", master_url, master_token))
|
||||
for r in replicas:
|
||||
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])
|
||||
|
||||
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>")
|
||||
|
||||
html = (
|
||||
'<div style="display:flex; gap:1.5rem; flex-wrap:wrap; margin-bottom:1rem; font-size:0.95em;">'
|
||||
+ " · ".join(parts)
|
||||
+ "</div>"
|
||||
) if parts else ""
|
||||
return HTMLResponse(html)
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def dashboard(request: Request, session: Session = Depends(get_session)):
|
||||
replicas = session.exec(select(Replica)).all()
|
||||
|
||||
Reference in New Issue
Block a user