Bugfix/17653 assets transforms and eager loading #17715
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Part 1:
Adjusts
Asset::getUrlsBySize()(which is used byAsset::getSrcset()) to get the base size (from the transform or original image, if there’s no transform defined) and all the requested sizes, and callsCraft::$app->getImageTransforms()->eagerLoadTransforms()with that info.Part 2:
Allows
trueto be passed towithTransforms(). If that’s the case, all the image transforms for the provided assets will be eager loaded.Both options keep the number of DB queries independent of the number of needed sizes/transforms (once the transforms have been created).
Code examples:
getSrcset()that preloads all existing image transform indexes)withTransforms(true)to preload all existing image transform indexesRelated issues