mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
fix(measurements): re-warm status assessments from every measurement write
The MCP writes, the Telegram reply, the CSV and backup importers and the Apple export import refreshed the rollups by hand and never re-warmed the cached status assessments, so a reading logged there kept the day's old assessment until the nightly pass. They now run the shared post-write tail, and the export import re-warms every type it wrote. The WHOOP body sync removed its legacy weight row without refolding that day; it does now. A structural test lists every file that writes measurements and how it keeps both readers current, so a new write site fails until it says.
This commit is contained in:
1 parent
4e7beb797c
commit
c88754a0b5
10 files changed
+318
-102
No files matched your search
@@ -11,10 +11,7 @@ import {
|
||||
parseCsvMeasurements,
|
||||
type CsvRowResult,
|
||||
} from "@/lib/import/csv-measurements";
|
||||
import {
|
||||
collapseToTypeDayKeys,
|
||||
recomputeBucketsForMeasurement,
|
||||
} from "@/lib/rollups/measurement-rollups";
|
||||
import { afterMeasurementMutation } from "@/lib/rollups/after-measurement-mutation";
|
||||
import type {
|
||||
MeasurementType,
|
||||
GlucoseContext,
|
||||
@@ -317,24 +314,10 @@ export const POST = apiHandler(async (request: NextRequest) => {
|
||||
}
|
||||
|
||||
// One bounded rollup re-fold per touched (type, day) — a 10 000-row CSV
|
||||
// pays at most ~N (type, day) recomputes, not 10 000 per-row hooks.
|
||||
// Best-effort: a populator hiccup never fails the importer.
|
||||
if (touchedMeasurements.length > 0) {
|
||||
try {
|
||||
const keys = collapseToTypeDayKeys(touchedMeasurements);
|
||||
for (const k of keys) {
|
||||
await recomputeBucketsForMeasurement(userId, k.type, k.measuredAt);
|
||||
}
|
||||
} catch (err) {
|
||||
annotate({
|
||||
meta: {
|
||||
measurement_rollup_csv_import_failed: true,
|
||||
measurement_rollup_csv_import_error:
|
||||
err instanceof Error ? err.message : String(err),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
// pays at most ~N (type, day) recomputes, not 10 000 per-row hooks — and
|
||||
// the status re-warm for the touched types. Best-effort: a populator
|
||||
// hiccup never fails the importer.
|
||||
await afterMeasurementMutation(userId, touchedMeasurements, "import.csv");
|
||||
|
||||
await auditLog("import.csv.upload", {
|
||||
userId,
|
||||
|
||||
Reference in new issue
Block a user