Skip to content

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

Merged
taylorotwell merged 2 commits intolaravel:5.8from
Mushr0000m:feature/morph-to-eager-loading-performance
Jul 10, 2019
Merged

[5.8] Improve eager loading performance for MorphTo relation#29129
taylorotwell merged 2 commits intolaravel:5.8from
Mushr0000m:feature/morph-to-eager-loading-performance

Conversation

@Mushr0000m
Copy link
Copy Markdown
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
Comment thread src/Illuminate/Database/Eloquent/Relations/MorphTo.php Outdated
Co-Authored-By: Jonas Staudenmeir <mail@jonas-staudenmeir.de>
@taylorotwell taylorotwell merged commit 64917b5 into laravel:5.8 Jul 10, 2019
@driesvints
Copy link
Copy Markdown
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
Copy Markdown
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