-
Notifications
You must be signed in to change notification settings - Fork 228
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
Fix N+1 problem for one-to-many and many-to-many relationships #254
Conversation
The approach with using |
@Nabellaleen Thanks for reviewing. Apologies for the not replying earlier - I got sidetracked by a concurrency bug in Promise and Dataloader that was breaking batching. Once this PR is merged, I'm going to work on setting up benchmarks to compare with and without batching. |
I have 2 followup PRs that are currently blocked on this one:
I'll be sending those once this one is approved because AFAIK Github does not allow working with "stacked" PRs. Cheers |
This re-uses all the batching logic implemented in #253.
This optimization batches what used to be multiple SQL statements into a single SQL statement. While this this an improvement over the previous behavior, there is still some room for more optimizations:
For now, I decided to put this into a separate
BatchSQLAlchemyConnectionField
because the...ConnectionField
classes need to be refactored a bit in order to allow people to easily opt-out of the batching behavior if need be (via theORMField
mechanism). I'll be addressing this in a follow up PR soon. For now, you'll have to enable the optimization via theSQLAlchemyObjectType.Meta.connection_field_factory
(seetest_batching.py
).Cheers