fix(db): materialize includes into parent rows before commit #1684
Closedjuliuslipp(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/1684/headopened - @@ -1238,3 +1243,18 @@12381243 return state.materialization !== `collection`12391244 }124012451246+/**1247+ * Materializes the current includes state into freshly computed parent rows1248+ * before they are committed, so the emitted change events already carry1249+ * their included values.1250+ *1251+ * The post-commit includes flush patches stored parent rows in place without1252+ * emitting an event, which consumers that copy rows at emit time (e.g.1253+ * another live query layered on this collection) never observe: a1254+ * parent-only update would wipe their included fields until an unrelated1255+ * child change re-emitted the row.1256+ */1257+function patchParentChangesFromIncludes(1258+ includesState: Array<IncludesOutputState>,1259+ parentChanges: Map<unknown, Changes<any>>,1260+): void {@@ -713,0 +737,21 @@737+ const layered = createLiveQueryCollection((q) =>738+ q.from({ row: collection }),739+ )740+ await layered.preload()741+742+ expect(sortedPlainRows((layered.get(1) as any).issues)).toEqual([743+ { id: 10, title: `Bug in Alpha` },744+ { id: 11, title: `Feature for Alpha` },745+ ])746+747+ // Update only the parent row; no child rows change.748+ projects.utils.begin()749+ projects.utils.write({750+ type: `update`,751+ value: { id: 1, name: `Alpha renamed` },752+ })753+ projects.utils.commit()754+755+ await new Promise((resolve) => setTimeout(resolve, 10))756+757+ const renamed = layered.get(1) as any
juliuslipp(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
4c03308a-8d39-481b-87c0-bedd0db3d783📥 Commits
Reviewing files that changed from the base of the PR and between a9761370040a3fb0e75e724539922db918259726 and c8d03e445863bc355ef08d2e5a4bf657424f6c1e.
📒 Files selected for processing (2)
packages/db/src/query/live/collection-config-builder.tspackages/db/tests/query/includes.test.ts🚧 Files skipped from review as they are similar to previous changes (2)
📝 Walkthrough
Walkthrough#
The live query flush now materializes inline includes into parent changes before commit and emission. A regression test verifies layered queries retain included child rows after parent-only updates, and the changeset documents the fix for issue 1635.
Changes#
Live query include materialization
packages/db/src/query/live/collection-config-builder.ts,.changeset/heavy-pandas-tell.mdpackages/db/tests/query/includes.test.tsEstimated code review effort: 2 (Simple) | ~10 minutes
Possibly related issues
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#1635by fixing nested includes after parent-only updates and adding a regression test.✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share