mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
POST /api/measurements/batch ran one interactive reconciler transaction per fresh sample: a savepoint, three advisory locks, two candidate reads and the insert, about ten round trips. A 500-entry upload of new samples was 500 of those, the 2 to 15 second outliers. Fresh samples now land through INSERT ... ON CONFLICT DO NOTHING under the same per-account advisory lock. Both measurement identities are full unique indexes, so the statement inserts exactly what the reconciler would have inserted, and every skipped row still goes through the reconciler for its own verdict. Only rows whose external and natural keys each occur once in the batch are buffered, and the buffer is flushed before any other row is reconciled, so the order of effects stays the sequential one. The contract and every per-entry status are unchanged; a golden test runs each batch through both paths against the same table. /api/health took seconds after a start because register() awaited the whole pg-boss worker start (queues, schedules, boot discovery) before the server took a request. The worker, or a web process's producer, now starts in the background after the blocking boot checks; the probe answers at once with reason "starting" until it is up, and gives the database two seconds before calling it not answering.
3.1 MiB
3.1 MiB