load cascade child once per ref in fk cascade delete#64
Merged
Conversation
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.
Summary
Closes #23. In FK cascade-delete, each referencing child entity was read from storage twice: once inside
is_cross_ownedto check the owner field, then again incollect_delete_operationsto deserialize for recursive cascade. Both reads used identical keys.Replaced
is_cross_ownedwithclassify_cascade_child, which loads the record once and returns a three-variantCascadeChildenum:Skip— cross-owned, don't recurse, don't push a Cascade opMissing— record gone (e.g. concurrent delete), push Cascade op without recurseRecurse(Entity)— proceed with cascade using the already-loaded entityThe caller pattern-matches and only needs to push the Cascade op (and recurse when applicable); no second
storage.get/Entity::deserializeper child.Per-child read counts:
Saves one read per same-owner child (the common path under ownership-aware cascade) and per missing-record-with-ctx.
Test plan
cargo make clippy— clean (pedantic, all targets + wasm)cargo test -p mqdb-agent --test constraint_test— 34/34 pass, including all owner-aware cascade scenarios (same-owner deletes, cross-owner survives, admin bypass, no-sender blind, mixed-ownership multilevel)