mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-07 04:12:04 +00:00
Long-term retention for the dense intra-day tier (PULSE, HRV, SpO2) folds to per-local-hour means instead of a single daily mean: the last 14 days keep every raw sample, older days keep up to 24 points per metric — the day's shape survives permanently at ~9k rows/metric/year. Hourly rows key as stats:<HK>:<YYYY-MM-DD>T<HH> anchored at local HH:30, adopt-in-place against both unique indexes with the P2002 retry outside the transaction. The pre-fold DAY-rollup recompute extends to HRV (mean fidelity, not only min/max) and the post-fold recompute is gone for the whole tier. Derived resting rows for proxy users still mint from the day's raw samples. A one-shot rebuild reconstructs the hourly shape for every already-folded day from the soft-deleted raw samples and retires the daily row in the same transaction — at no instant are both grains live, so no AVG-over-live-rows reader can double-count. Boot discovery pairs live daily-grain rows with surviving tombstones (parameter-bound SQL, pinned against real Postgres) and converges to zero once converted; days whose tombstones were pruned keep their daily mean. PULSE/SpO2 DAY buckets keep the true pre-fold stats; HRV DAY buckets recompute from the hourly rows (strictly better than the collapsed fold-time bucket); WEEK/MONTH/YEAR respans enqueue whole-bucket recomputes.
954 KiB
954 KiB