mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
Pre-fix the dashboard mounted two separate consumers against the same `/api/mood/analytics` endpoint: `app/page.tsx:291` keyed on `queryKeys.moodAnalytics()` (`["mood-analytics"]`) and the chart at `mood-chart.tsx:316` keyed on a bare `["mood-chart-data"]` literal. TanStack treats different keys as separate cache slots, so a cold dashboard mount fired two requests against the same endpoint — wasting one HTTP round trip, one pg pool slot, and ~22 KB of payload per cold mount (empirical-trace #3). Re-key the chart to `queryKeys.moodAnalytics()` so TanStack dedups the request; align the chart's `staleTime` to the dashboard's 60 s window so a route swing back to the dashboard within a minute stays a free cache hit. The chart's own subscription becomes the cache writer for any insights / mood sub-page that mounts it without the dashboard parent having fetched first. No payload-shape change — the chart already typed its response as `MoodAnalyticsData` which matches the dashboard's `{ entries, summary }` shape byte-for-byte.