From cc5c700921057055e44cd3456811ac80f832f056 Mon Sep 17 00:00:00 2001 From: Robert Helewka Date: Sat, 11 Apr 2026 19:24:46 +0000 Subject: [PATCH] refactor(server): replace legacy sync endpoint with cache refresh Replaces legacy API-Football DB sync logic with cache invalidation. New endpoint clears DB and API caches, forcing fresh data fetch on next request. Updates dashboard button text and icon to reflect 'Refresh Cache'. Adjusts toast and result messages to report cache clearing duration. --- nike/server.py | 15 +++++++++++++++ nike/templates/dashboard.html | 15 +++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/nike/server.py b/nike/server.py index c058771..7fcc8be 100644 --- a/nike/server.py +++ b/nike/server.py @@ -849,6 +849,21 @@ async def api_cache_invalidate(): }) +@dashboard.post("/api/sync") +async def api_sync(): + """Cache refresh — replaces the legacy API-Football DB sync.""" + start = time.perf_counter() + db.invalidate_cache("%") + api.clear_cache() + duration = round(time.perf_counter() - start, 2) + return JSONResponse({ + "ok": True, + "result": {"players": 0, "seasons": {}}, + "duration_s": duration, + "note": "Cache cleared; fresh data will be fetched on next request.", + }) + + # ── Tool runner API ─────────────────────────────────────── _TOOLS: dict[str, Any] = {} # populated after tool definitions exist diff --git a/nike/templates/dashboard.html b/nike/templates/dashboard.html index 56103d9..4f3f3bc 100644 --- a/nike/templates/dashboard.html +++ b/nike/templates/dashboard.html @@ -225,7 +225,7 @@
@@ -437,29 +437,28 @@ const btn = document.getElementById('syncBtn'); const result = document.getElementById('syncResult'); btn.disabled = true; - btn.innerHTML = 'Syncing…'; + btn.innerHTML = 'Refreshing…'; result.textContent = ''; - document.getElementById('syncToastBody').textContent = 'Sync started — this takes ~10 seconds…'; + document.getElementById('syncToastBody').textContent = 'Clearing cache…'; toast.show(); try { const resp = await fetch('/api/sync', { method: 'POST' }); const data = await resp.json(); if (data.ok) { - const r = data.result; - result.innerHTML = `✅ Synced ${r.players} players, ${Object.values(r.seasons || {}).reduce((a,b)=>a+b,0)} fixtures in ${data.duration_s}s`; - document.getElementById('syncToastBody').textContent = `Sync complete in ${data.duration_s}s`; + result.innerHTML = `✅ Cache cleared in ${data.duration_s}s`; + document.getElementById('syncToastBody').textContent = `Cache cleared in ${data.duration_s}s`; await refreshStatus(); } else { result.innerHTML = `❌ ${data.error}`; - document.getElementById('syncToastBody').textContent = 'Sync failed: ' + data.error; + document.getElementById('syncToastBody').textContent = 'Refresh failed: ' + data.error; } } catch (e) { result.innerHTML = `❌ Network error`; } finally { btn.disabled = false; - btn.innerHTML = 'Sync TFC Data'; + btn.innerHTML = 'Refresh Cache'; } }