Skip to content

Add subtrees_of scope for batch subtree queries - #767

Open
stevecrozz wants to merge 1 commit into
stefankroes:masterfrom
stevecrozz:add-subtrees-of-scope
Open

Add subtrees_of scope for batch subtree queries#767
stevecrozz wants to merge 1 commit into
stefankroes:masterfrom
stevecrozz:add-subtrees-of-scope

Conversation

@stevecrozz

@stevecrozz stevecrozz commented Aug 14, 2026

Copy link
Copy Markdown

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])

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

  • Feature

Checklist

  • My code follows the style guidelines (e.g., RuboCop)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally (bundle exec rake test)

How Has This Been Tested?

Wrote unit tests (included), also tested in my own application which uses this gem

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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant