Skip to content

fix: prevent stale analytics data and add session auto-refresh#199

Merged
vakovalskii merged 1 commit intovakovalskii:mainfrom
NovakPAai:claude/jack-fix-stale-analytics-data
Apr 21, 2026
Merged

fix: prevent stale analytics data and add session auto-refresh#199
vakovalskii merged 1 commit intovakovalskii:mainfrom
NovakPAai:claude/jack-fix-stale-analytics-data

Conversation

@NovakPAai
Copy link
Copy Markdown
Collaborator

Problem

Two staleness bugs reported by users:

  1. Analytics tab showed stale data_analyticsHtmlCache was never invalidated after the initial render, so navigating away and back always showed the same cached HTML without refetching from /api/analytics/cost.

  2. Activity heatmap and analytics never updatedallSessions was loaded once at startup and then only on manual Refresh click. New sessions created while the dashboard was open were never reflected.

Changes

  • Cache invalidation: loadSessions() now clears _analyticsHtmlCache and _analyticsCacheUrl on every successful fetch, so the Analytics tab refetches on next visit.
  • Auto-refresh: setInterval(loadSessions, 60000) added in init() — sessions, activity heatmap, and analytics stay current automatically.
  • In-flight guard: _loadSessionsInFlight flag prevents overlapping fetches when setInterval and the X-Loading progressive auto-refresh fire at the same time (e.g. after laptop sleep/wake).

Test plan

  • Open Analytics, note the data, wait 60s or click Refresh — data updates
  • Open Activity heatmap, start a new session in another terminal, wait up to 60s — new day appears without manual refresh
  • Throttle network to Slow 3G in DevTools, verify only one /api/sessions request is in-flight at a time (no duplicate requests in Network tab)

- 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
Copy link
Copy Markdown
Owner

@vakovalskii vakovalskii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix — in-flight guard + cache invalidation + finally block. LGTM.

@vakovalskii vakovalskii merged commit 3ee4cc5 into vakovalskii:main Apr 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants