mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
The chart-data query in health-chart.tsx walked the full measurement history with a `while (true)` paginated loop on every visit. For Apple-Health-rich accounts (pulse every minute, months of backfill) this meant tens of thousands of rows per type per page navigation, which is the root cause behind FB-D2's "pulse insights loads forever" report. Derive `from` / `to` from the active range tab (plus the comparison-baseline shift when overlay is on), pass both to /api/measurements, and drop the unbounded paginator. The query key re-keys on the window so a range-tab change refetches the right slice. staleTime 60s + gcTime 5min hold the bounded payload across tab navigation between insights sub-pages. New `aggregate` query param + range-aggregation helper let the GET handler downsample server-side for ranges over 90 d (one row per day) and over 365 d (one row per ISO week). The per-request `limit` ceiling lifts from 500 to 5000 — still bounded, but enough headroom for an explicit from/to window without re-introducing pagination. iOS contract — GET /api/measurements: additive. The `from`, `to`, `aggregate` params are all optional; callers that omit them (the iOS client, the existing measurements page) see the unchanged response shape and the historical 500-row default cap. The aggregated branch is only entered when both from + to are present AND the window is wide enough for the threshold ladder to engage.