mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
buildComparisonSnapshotForUser read a user's entire measurement history per type with no date floor, then fed each series to summarize(). The snapshot only consumes avg30 / avg30LastMonth / avg30LastYear, and the widest of those reaches into the [365, 395)-day window (ageMs < 395 days in meanOfWindow), so nothing older than 395 days can change a result. Add a 400-day measuredAt.gte lower bound to every per-type read in both copies of the builder — the page-blocking POST /api/insights/generate handler and the shared comprehensive-generate path the nightly pregenerate cron drives. The fan-out runs all seven snapshot types via Promise.all, so on multi-year accounts the unbounded scan was tens of thousands of rows per type. 400 days keeps a 5-day floor over the strict-less-than 395-day reach.