mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
`bmi`, `pulse`, `general`, `weight`, `blood-pressure`, and `mood` status helpers all built their `summarizeSeries` block with `Math.min(...series.map(...))` and `Math.max(...series.map(...))`. The same anti-pattern hit `summarize()` in `src/lib/analytics/trends.ts` on 2026-05-16 and crashed `/api/analytics` with `RangeError: Maximum call stack size exceeded` once an Apple-Health-synced PULSE series outgrew V8's ~125 000-arg ceiling; `61107e0c` folded that one. The six insight helpers are fed bounded windows today so they never reached the ceiling, but the spread still allocates a transient args array on every call and the fold is both stack-safe and cheaper. Replace each `Math.min(...) / Math.max(...) / average(...)` triplet with a single walk that maintains running sum / min / max. The now-unused `average()` helper is dropped from each file. Pinned by the existing per-helper unit tests (326 passing in `src/lib/insights` / `src/lib/analytics` / `src/app/api/analytics`).