Repository navigation
fix(orm): bound aggregate read caches to safe write scopes - #451
Conversation
Bulk statements reconciled aggregate buckets per document: a 40-row update issued ~80 index probes against one aggregate_bucket row. Every document is reconciled in its own change hook, so folding the delta array removes nothing; the fix is transaction lifetime for the two point lookups. - memoize getBucketByKey/getMemberByDoc on the createOrmTransactionMemo anchor, write path only. readPlanBuckets stays unmemoized: its 25-wide fan-out can store a pre-write row over a write-through entry, for no measured gain - write through on every delta writer; patch merges onto the whole prior row so keyHash survives for the extrema reads - thread docId + the member post-image through AggregateMembershipDelta; the patch/delete member writes carried no docId, so write-through was otherwise unimplementable and would have corrupted counts - clearCountIndexChunk retires entries exactly; it deletes without going through the delta machinery and its callers only bump state afterwards 12-row bulk update across two orgs: 2 bucket probes, was 24. Values unchanged.
🦋 Changeset detectedLatest commit: b62b80c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Autoclosure proof receipt — head Local HEAD, fetched Feedback read-back: helper 0 threads / 2 comments / 0 reviews; unfiltered 0 Exact item verdicts:
Auto release is unchecked. CI and Preview are still running; this receipt does |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Autoclosure terminal receipt — head Supersedes the predecessor-head receipt. Local HEAD, fetched Full Fresh feedback inventory: helper 0 threads / 4 comments / 0 review bodies; Exact item verdicts:
Auto release is unchecked. Merge uses |
🐛 Addresses #440 — aggregate read amplification.
🧭 Task plan: docs/plans/440-memoize-aggregate-bucket-and-member-reads.md
🟢 High confidence — local proof passes; hosted checks verified before merge.
✅ Outcome
Bulk ORM writes reuse aggregate bucket and member rows within uninterrupted
statements. A 12-row insert or delete probes one bucket; an update moving rows
between two key tuples probes two. Indexed counts remain correct across nested
mutations, including calls made inside lifecycle hooks and RLS policies.
🏗️ Design
Statement builders own cache lifetime. User lifecycle and policy callbacks
expire cached rows and suspend reuse until the callback settles, including
reentrant statements. Aggregate maintenance updates cached post-images after
writes and invalidates cleared rows. Query reads continue to read storage.
🧪 Verified
bun checkpasses: 1403 Bun tests, 1014 Vitest tests, 124 CLI tests, eightfixture comparisons and generated-app runtime checks. Focused proof covers
66 integration/memo cases plus three cache-lifetime exception tests. Root
typecheck, lint, package build, intent validation/staleness and rendered docs
inspection pass. Final P1 review and exact-head GitHub receipts are recorded
before merge.