Skip to content
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

[5.8] Improve eager loading performance for MorphTo relation #29129

Merged

Conversation

@Mushr0000m
Copy link
Contributor

commented Jul 10, 2019

Refering to PR #26434
I had the same issue, where the whereIn done in the query with my morphTo eager loading very slow.

I updated the getResultsByType() method in Illuminate\Database\Eloquent\Relations\MorphTo.php to use the same logic than the one in addEagerConstraints() method from Illuminate\Database\Eloquent\Relations\HasOneOrMany.php. By doing so, depending on the PK type the method uses whereIntegerInRaw or whereIn.

It decreased my query execution time from 1.8s for 34000 records to 12ms.

Also I found that on our project that is a 5.7 version, would it be possible to apply this PR to 5.7 as well ?

@GrahamCampbell GrahamCampbell changed the title Improve eager loading performance for MorphTo relation [5.8] Improve eager loading performance for MorphTo relation Jul 10, 2019

Use model instance instead of parent
Co-Authored-By: Jonas Staudenmeir <mail@jonas-staudenmeir.de>

@taylorotwell taylorotwell merged commit 64917b5 into laravel:5.8 Jul 10, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@driesvints

This comment has been minimized.

Copy link
Member

commented Jul 11, 2019

Also I found that on our project that is a 5.7 version, would it be possible to apply this PR to 5.7 as well?

@Mushr0000m No, 5.7 isn't supported anymore. Please upgrade.

@LasseRafn

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2019

🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.