Repository navigation
Add bulk_create_has_child store primitive for the batched edge sweep (sync #345) - #1707
Merged
mstomar125 merged 2 commits intoJul 20, 2026
Merged
Conversation
The reconnect relationship sweep applies has_child edges one at a time (create_parent_edge → move_node, per-row), which is the dominant cost of a large cold pull (~133 edges/s in a 33k-edge tenant) once the node apply is batched. Add the store primitive `SqliteStore::bulk_create_has_child(&[(parent, child, order)])` — one transaction, idempotent (skips a child that already has a parent, so it never re-parents), direction `in_node = parent, out_node = child` matching move_node / get_children, order stored at `properties.$.order` (get_children sorts by it, so a fresh parent's children reproduce the sender's sibling order). Plus a NodeService wrapper `bulk_create_has_child_edges` that emits one RelationshipCreated per created edge (matching the per-row path), coalesced by the caller's begin_batch_emit guard. This is intended for the from-scratch (cold) sweep where every parent is fresh; repositioning / non-fresh parents stay on the per-row path. Test proves sibling order is reproduced and re-runs are idempotent (no re-parent). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…iew) Review notes: (1) the wrapper doc claimed RelationshipCreated events are coalesced by begin_batch_emit — they aren't (relationship events are not node-keyed, so they broadcast immediately, one per edge, exactly as the per-row create_parent_edge does; the batching win is the single transaction). Corrected the comment. (2) Added a test proving the store's read-your-writes skip-check prevents a second parent edge when the same child appears under two parents within ONE batch (attaches to the first only). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Contributor
Author
Adversarial review + resolutionVerified all seven correctness points against
Addressed the two non-blocking notes (commit): corrected the doc comment (relationship events broadcast immediately, NOT coalesced by |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Foundation for nodespace-sync#345 (batch the reconnect edge sweep). The pull's node apply is already batched (sync #338); the
has_childedge apply is still per-row (create_parent_edge→move_node, one write each) and is now the dominant cost of a large cold pull (~133 edges/s in a 33k-edge tenant).Change
SqliteStore::bulk_create_has_child(&[(parent, child, order)])— insert manyhas_childedges in ONE transaction. Direction matchesmove_node/get_children(in_node = parent, out_node = child), order stored atproperties.$.order(whichget_childrensorts by ASC), so a fresh parent's children reproduce the sender's sibling order exactly. Idempotent: a child that already has a parent is skipped (a node has at most one parent) — it never re-parents.NodeService::bulk_create_has_child_edges(&[(parent, child, order)])— thin wrapper that emits oneRelationshipCreatedper created edge (matching the per-row path), coalesced by the caller'sbegin_batch_emitguard.Intended for the from-scratch (cold) sweep where every parent is fresh, so the sender's
ordervalues are the final sibling order. Repositioning / non-fresh parents stay on the per-rowcreate_parent_edge.Tests
bulk_create_has_child_edges_reproduces_order_and_is_idempotent: attach children out of order (b=1, a=2, c=3) →get_childrenreturns [b,a,c]; a re-run skips already-parented children (0 created, order unchanged). Fullnodespace-corelib suite (962) green; clippy + fmt clean; pre-push gate passed.The sync-side integration (batch the cold rel sweep, per-row fallback) follows in nodespace-sync#345.
🤖 Generated with Claude Code