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

Eager loading asset transforms doesn't work (with potential fix) #4931

Closed
smcyr opened this issue Sep 12, 2019 · 4 comments
Closed

Eager loading asset transforms doesn't work (with potential fix) #4931

smcyr opened this issue Sep 12, 2019 · 4 comments

Comments

@smcyr
Copy link

smcyr commented Sep 12, 2019

Description

I try to eager load asset transforms in a matrix and with or without the eager loading, the number of queries stay the same.

I checked in the code and in the method eagerLoadElements of Elements.php line 1694, the asset query is executed with asArray. In the method populate of AssetQuery.php, the withTransforms is skipped if asArray is true. So, if I comment asArray() in Elements.php, it's now working as intended.

Update: It seems the the culprit is this commit from 14 days ago:
ec292df#diff-a23f034d2592a363d6ae402cff459928

Steps to reproduce

  1. Create a matrix field with an asset field inside
  2. Loop in the matrix while eager loading the asset with withTransforms

Additional info

  • Craft version: 3.3.2
  • PHP version: 7.3.5
  • Database driver & version: MySQL 5.5.5
  • Plugins & versions:
@brandonkelly
Copy link
Member

Thanks for reporting that! I’ve just fixed it for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#a6be2dc6349cdfd829a46b216f38d47a304ecca1 as 3.3.3",
  "...": "..."
}

Then run composer update.

@smcyr
Copy link
Author

smcyr commented Sep 12, 2019

Wow, that was fast! Thanks, it's working!

@rmales
Copy link

rmales commented Nov 12, 2020

I'm trying to debug some problems we're having with eager loading image transforms and came across this issue. It seems like the fix here was reverted at some point. Now it looks to me like because of this withTransforms doesn't work on nested fields, e.g. with code like:

{% set authors = entry.authors.with([
    ['profileImage', { withTransforms: ['avatarX1', 'avatarX2'] }],
]).all() %}

@gromgull
Copy link

Can confirm - it no longer works in 3.5.16 :(

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

No branches or pull requests

4 participants