-
Notifications
You must be signed in to change notification settings - Fork 27
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
Smart eager loading #172
base: master
Are you sure you want to change the base?
Smart eager loading #172
Conversation
13ad614
to
f51198b
Compare
This will allow us in the future to build a oneToMany handler for smart eager loading.
fa7685f
to
a816e5b
Compare
First of all, hats of to you. This is a pretty smart solution, if it works for every day code. Since there's no comment function on the article on thecodingmachine.io, I'll ask it here, since it wasn't covered in the article. What happens, if we have an object with multiple relations?
Will it issue one query for |
Hey Pascal! In your example, there would be 3 requests I think:
We could try to run only one query instead of 3, but that would generate a lot of book keeping indeed. Actually, trying to perform 1 query instead of 3 could lead to performance issues. This is a documented bottleneck in Doctrine ORM for instance (see https://tideways.com/profiler/blog/5-doctrine-orm-performance-traps-you-should-avoid) |
This PR adds a new feature: Smart Eager Loading.
The idea behind smart eager loading is to track the origin of each bean. If a bean originates from a result set, when a related bean is accessed (through a foreign key), instead of quering only the data related to the bean, we query the data related to all related beans.
This optimisation allows us to jump from N+1 queries to only 2 queries \o/