-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid N + 1 queries #140
Comments
This is not a ancestry issue, but with your code. You iterate over an array build from a query, so yes, you'll get N+1 queries where N is the size of that array. Category.where(:ancestry => Catergory.roots.pluck(:id)).all
# or if you have depth caching on:
Category.where(:ancestry_depth_cache => 1).all |
I understood @holstvoogd, but it is not so object oriented, right? |
sure, but that is how ActiveRecord works. the .each call causes the first query to execute and then you have a simple array, so N queries. |
But when I use |
If .includes() worked, rendering a collection wouldn't result in N+1 queries either. |
Sorry for reviving this issue but is there nowadays some integration for |
@alexanderadam I'm sorry to say that no. at this time there is no |
What a pity. Thank you for responding so fast. |
Hi guys,
First of all, thank you for the great work with this gem.
I have some performance issues here, because N + 1 queries using ancestry.
I have a model:
And I want to load all root categories loading all children of each one.
I want to execute only 2 queries here. I was looking for this into source code, but I didnt find it. Is there any plan to solve this performance issue?
Thank you.
The text was updated successfully, but these errors were encountered: