From 4c7caedcbf3b0f86563ebcfa3b82d34859f77b02 Mon Sep 17 00:00:00 2001 From: jackrescuer-gif Date: Sun, 19 Apr 2026 22:34:26 +0300 Subject: [PATCH] fix: prevent stale analytics data and add session auto-refresh - Invalidate _analyticsHtmlCache on every loadSessions() call so the Analytics tab always shows fresh data after navigating away and back - Add setInterval(loadSessions, 60000) so allSessions (used by Activity heatmap and Analytics) stays current without manual refresh - Guard loadSessions with _loadSessionsInFlight flag to prevent overlapping fetches when setInterval and the X-Loading progressive auto-refresh fire simultaneously --- src/frontend/app.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/frontend/app.js b/src/frontend/app.js index 3c6c318..39da5b9 100644 --- a/src/frontend/app.js +++ b/src/frontend/app.js @@ -447,10 +447,17 @@ function generateAllTitles() { // ── Data loading ─────────────────────────────────────────────── +var _loadSessionsInFlight = false; + async function loadSessions() { + if (_loadSessionsInFlight) return; + _loadSessionsInFlight = true; try { var resp = await fetch('/api/sessions'); allSessions = await resp.json(); + // Invalidate analytics cache so stale aggregates are not shown + _analyticsHtmlCache = null; + _analyticsCacheUrl = null; applyFilters(); // Progressive loading: if server is still loading cursor vscdb sessions, auto-refresh if (resp.headers.get('X-Loading') === '1') { @@ -458,6 +465,8 @@ async function loadSessions() { } } catch (e) { document.getElementById('content').innerHTML = '
Failed to load sessions. Is the server running?
'; + } finally { + _loadSessionsInFlight = false; } } @@ -1980,6 +1989,7 @@ function dismissUpdate() { loadTerminals(); checkForUpdates(); setInterval(checkForUpdates, 10000); // check every 10s + setInterval(loadSessions, 60000); // refresh sessions + invalidate analytics cache every 60s startActivePolling(); // Apply saved theme