mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
Three Withings ingest paths wrote measurements without ever firing the rollup write hook: `syncUserMeasurements`, `syncUserActivity`, and `syncUserSleep`. Once the dashboard chart's `source=rollup` fast-path landed in v1.4.36 the under-counting started biting Withings-only metrics on the 30 / 90-day range — Marc's BP / pulse charts painted the empty-state at 30 even though the live `measurements` table held the days. The 7-day window kept reading raw rows so the empty-state only appeared above the chart's `< 3 daily points` threshold. Each sync now collects every `(type, measuredAt)` it touched, collapses to distinct `(type, dayStart)` via `collapseToTypeDayKeys`, and calls `recomputeBucketsForMeasurement` once per pair after the row writes. The per-day collapse keeps a 30-day catch-up bounded — at most ~30 DAY recomputes per sync rather than one per row. Best-effort: a populator hiccup never fails the user's sync. - Tests pin the hook call count on activity (6 calls for 2 days × 3 metrics, 3 calls when the dates collapse) and sleep (one per night even when each night has multiple stage segments), plus a populator- failure path that proves the sync still returns its imported count. - Reproducer verified: stashing the sync-activity hook makes the new test red on develop; restoring it greens.