-
Notifications
You must be signed in to change notification settings - Fork 144
Description
Hi,
We've been getting hit hard with n+1 queries in our codebase and its been causing quite a few issues. We do a lot of nested includes in our models but I thought Graphiti was supposed to handle loading them without n+1 queries.
I set up a new codebase and mirrored some of our models/associations to see if I could work out what the cause of the issue is. And I've found that when the sideload_allowlist is used, the n+1 queries happen. When I remove it, eager loading is used correctly.
Please see this codebase: https://github.com/Reizar/graphiti-nplus1-example for a reproduction of the issue.
Steps to reproduce:
- Clone codebase linked above.
- Run
rails db:migrate
- Run
rails db:seed
- Run
rails server -p 5000
- Visit:
http://127.0.0.1:5000/api/v1/inspections?include=tenancy.tenancy_memberships.user,tenancy.property&page[number]=1&page[size]=100
You should see the rails console filled with tonnes of DB queries.
Then:
- Open up
app/controllers/inspections_controller.rb
- Comment out the self.sideload_allowlist = code
- Visit the url above again
- The queries should be reduced down to just the number of associations.
Feels like this is probably a bug, but it could also be an issue on our side of how we're using the sideload allowlist. Happy to hear any thoughts or provide additional information.