mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
chore(release): v1.28.25 — every integration held to the same standard
Platform-wide hardening: the failure classes found live this week hunted down across every integration. Fitbit carried the same tombstone wedge fixed for Google — probe now matches soft-deleted rows and the update resurrects them; the comment describing a partial unique index that never existed is corrected. Sleep segment ids are stable across re-scoring for Withings (session+segment-start), WHOOP/Polar (one segment per stage, no positional index) and Oura (run-start keyed), each with a session-scoped sweep that soft-deletes rows a re-score orphaned — so legacy and affected nights heal as they are re-read. One platform rule for deleted rows: source-owned readings resurrect on re-import (Withings, WHOOP, Oura, Polar, Nightscout, mood webhook, CSV re-imports, Apple stats day-totals); Apple sample-grain deletions stick per the paired-client contract, and the mood bulk route's tombstone match is now a true no-op reported as duplicate. Import counts reconcile against actual createMany counts. Google lifecycle: a dead token registers on the cycle's hard-fail ledger, so an expired connection parks instead of stamping success hourly; backfill and sleep-repair markers stamp only after a clean pass (pg-boss retries are now real); failed measurement writes hold the watermark; no-op updates are skipped; mapping.md tells the current truth. Scale: doctor-report reads only consumed columns and enabled sections; exports and backups keyset-paginate; achievements tally via SQL buckets; series charts day-bucket dense kinds beyond 90 days; BP pairing is a linear two-pointer; distinct-type scans run server-side; the graded-series cold fallback is bounded; the fitbit defer tracker loops instead of spreading.
This commit is contained in:
1 parent
1085a1e056
commit
9c63d3ce20
79 files changed
+3221
-564
No files matched your search
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
import type { PrismaClient } from "@/generated/prisma/client";
|
||||
import { readNote } from "@/lib/crypto/note-cipher";
|
||||
import { findMeasurementsPaged } from "@/lib/export/paged-measurements";
|
||||
import { BACKUP_SCHEMA_VERSION } from "@/lib/validations/backup";
|
||||
import { buildCycleBackupSection } from "@/lib/cycle/backup";
|
||||
|
||||
@@ -39,10 +40,28 @@ export async function buildFullBackupPayload(
|
||||
): Promise<FullBackupResult> {
|
||||
const [measurements, medications, intakeEvents, moodEntries, cycle] =
|
||||
await Promise.all([
|
||||
prisma.measurement.findMany({
|
||||
where: { userId, deletedAt: null },
|
||||
orderBy: { measuredAt: "desc" },
|
||||
}),
|
||||
// v1.28.25 — keyset-paginated read with a narrow select. The backup
|
||||
// is inherently whole-history, so on a CGM / per-sample-HR account the
|
||||
// previous single full-width `findMany` materialised a six-figure row
|
||||
// set in one shot. The chunked read accumulates the same rows in the
|
||||
// same `measuredAt desc` order; the payload FORMAT below is untouched
|
||||
// (restore compatibility). The select is exactly the fields the
|
||||
// serializer reads: type / value / unit / measuredAt / source + the
|
||||
// note columns `readNote` decrypts + the `id` cursor key.
|
||||
findMeasurementsPaged(
|
||||
prisma,
|
||||
{ userId, deletedAt: null },
|
||||
{
|
||||
id: true,
|
||||
type: true,
|
||||
value: true,
|
||||
unit: true,
|
||||
measuredAt: true,
|
||||
source: true,
|
||||
notes: true,
|
||||
notesEncrypted: true,
|
||||
},
|
||||
),
|
||||
prisma.medication.findMany({
|
||||
where: { userId },
|
||||
select: {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Keyset-paginated measurement reader for the export surfaces.
|
||||
*
|
||||
* The legacy exports (`GET /api/export`, `GET /api/export/measurements`, the
|
||||
* full-backup builder) read the user's ENTIRE measurement table in one
|
||||
* `findMany`. On a CGM + per-sample-HR account that is a six-figure row set
|
||||
* materialised by a single query — the v1.28.2x incident class. This helper
|
||||
* keeps the output row set (and its `measuredAt desc` order) identical while
|
||||
* bounding each database round-trip to `MEASUREMENT_EXPORT_PAGE_SIZE` rows:
|
||||
* the driver never buffers one giant result, and the event loop yields
|
||||
* between chunks.
|
||||
*
|
||||
* Ordering: `measuredAt desc, id desc`. The exports always sorted
|
||||
* `measuredAt desc`; the `id` tie-breaker makes the keyset cursor total (two
|
||||
* rows can share a timestamp) — for equal-timestamp rows the previous order
|
||||
* was unspecified heap order, so pinning it is not a behaviour change any
|
||||
* consumer could have relied on.
|
||||
*
|
||||
* The `select` MUST include `id` (the cursor key); the generic constraint
|
||||
* enforces it at compile time.
|
||||
*/
|
||||
import type { Prisma, PrismaClient } from "@/generated/prisma/client";
|
||||
|
||||
export const MEASUREMENT_EXPORT_PAGE_SIZE = 10_000;
|
||||
|
||||
export async function findMeasurementsPaged<
|
||||
S extends Prisma.MeasurementSelect & { id: true },
|
||||
>(
|
||||
db: PrismaClient,
|
||||
where: Prisma.MeasurementWhereInput,
|
||||
select: S,
|
||||
pageSize: number = MEASUREMENT_EXPORT_PAGE_SIZE,
|
||||
): Promise<Array<Prisma.MeasurementGetPayload<{ select: S }>>> {
|
||||
const rows: Array<Prisma.MeasurementGetPayload<{ select: S }>> = [];
|
||||
let cursorId: string | null = null;
|
||||
for (;;) {
|
||||
const batch: Array<Prisma.MeasurementGetPayload<{ select: S }>> =
|
||||
(await db.measurement.findMany({
|
||||
where,
|
||||
orderBy: [{ measuredAt: "desc" }, { id: "desc" }],
|
||||
take: pageSize,
|
||||
...(cursorId !== null ? { cursor: { id: cursorId }, skip: 1 } : {}),
|
||||
select,
|
||||
})) as Array<Prisma.MeasurementGetPayload<{ select: S }>>;
|
||||
// Loop, not `push(...batch)` — a 10k-element spread is fine today, but
|
||||
// this file exists because of stack-overflow-by-spread regressions on
|
||||
// large arrays (v1.28.22 class); keep the pattern boring.
|
||||
for (const row of batch) rows.push(row);
|
||||
if (batch.length < pageSize) break;
|
||||
cursorId = (batch[batch.length - 1] as { id: string }).id;
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
Reference in new issue
Block a user