From 017368178691ef60851b4ad6310c2b0cb2496ca6 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 15 May 2026 17:03:30 +0200 Subject: [PATCH] feat: auto-reload grid when background cache refresh completes Poll /api/cache-ts every 30s; silently reload concerts if the cache timestamp increased (background scrape finished). Co-Authored-By: Claude Sonnet 4.6 --- main.py | 6 ++++++ static/app.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/main.py b/main.py index 7371862..6940ec2 100644 --- a/main.py +++ b/main.py @@ -90,6 +90,12 @@ async def api_concerts(page: int = 1, search: str = "", page_size: int = 24, cat return await fetch_concerts(page=page, search=search, page_size=page_size, category=category) +@app.get("/api/cache-ts") +async def api_cache_ts(): + from arte_api import _cache + return {"ts": _cache["ts"], "count": len(_cache["data"])} + + @app.post("/api/refresh") async def api_refresh(): count = await invalidate_cache() diff --git a/static/app.js b/static/app.js index 0599139..d9c2934 100644 --- a/static/app.js +++ b/static/app.js @@ -449,8 +449,25 @@ document.addEventListener('keydown', e => { } }); +// ── Cache auto-update polling ───────────────────────────────────────────────── +let _cacheTs = 0; + +async function pollCacheTs() { + try { + const { ts, count } = await fetch('/api/cache-ts').then(r => r.json()); + if (_cacheTs && ts > _cacheTs && count > 0) { + _cacheTs = ts; + await refresh(); + } else if (!_cacheTs) { + _cacheTs = ts; + } + } catch {} +} + // ── Init ───────────────────────────────────────────────────────────────────── (async () => { await Promise.all([loadCategories(), refreshDlHistory()]); await refresh(); + _cacheTs = (await fetch('/api/cache-ts').then(r => r.json()).catch(() => ({ts:0}))).ts; + setInterval(pollCacheTs, 30_000); })();