Add subtrees_of scope for batch subtree queries - #767
Open
stevecrozz wants to merge 1 commit into
Open
Conversation
Adds a class-level scope that returns the union of subtrees for multiple
nodes in a single query. Useful when fetching descendants of several
nodes at once without issuing N separate queries.
Model.subtrees_of([node_a, node_b, node_c])
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.
Adds a class-level scope that returns the union of subtrees for multiple nodes in a single query. Useful when fetching descendants of several nodes at once without issuing N separate queries.
Description
It can be at least slightly tricky to figure out how to efficiently grab subtrees from multiple roots. This is useful for bulk operations when operating on many roots at once.
Before
Either you figure out something similar yourself, or issue multiple queries. For a large set of roots the number of round trips can add up to poor performance.
After
Now we have a scope like Folder.subtrees_of(folders) so if a user selects 100 folders and wants to recursively operate on all of them, we have an easier way to do this.
Type of Change
Checklist
bundle exec rake test)How Has This Been Tested?
Wrote unit tests (included), also tested in my own application which uses this gem