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
merged 2 commits into from
Jul 10, 2019
Merged

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

merged 2 commits into from
Jul 10, 2019

Conversation

Mushr0000m
Copy link
Contributor

@Mushr0000m Mushr0000m 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
Co-Authored-By: Jonas Staudenmeir <mail@jonas-staudenmeir.de>
@taylorotwell taylorotwell merged commit 64917b5 into laravel:5.8 Jul 10, 2019
@driesvints
Copy link
Member

driesvints 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
Copy link
Contributor

🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants