UPSTREAM FIX

magento2-40388: Generates only the requested resized image when a missing cache URL is opened

Community fix magento2-40388 merged into magento/magento2 on 2026-07-06, not in a release yet; applies cleanly to 2.4.9.

Generates only the requested resized image when a missing cache URL is opened edited

Pull request title
Improve performance when resized image URL is accessed but does not yet exist.
Pull request
magento/magento2#40388
Issues
#40399 pr-derived
Author
@rogerdz
Merged
2026-07-06
Fixed in
no release yet
Reported on
—
Categories
Content
Components
magento/module-media-storage

Labels

Area
Content / CMS
Component
Image
Priority
P2
Severity
—
Reported on (labels)
2.4.x

Issue

Title and steps come from the upstream issue and pull request.

Description

Default Magento generate resize image for all image id (example:product_base_image , product_swatch_image_large, product_page_more_views, ...) when resized image URL is accessed but does not yet exist.
This increases response time and disk I/O.
Test with PR when accessing one missing resized image URL, response time decreased from 1s to 150ms

Steps to reproduce

1. Remove all product resize image: rm -rf pub/media/catalog/product/cache/*
2. Go to any resize image (example: https://magento2.test/media/catalog/product/cache/2765542505660baab28ecd555e27366e/w/t/wt09-white_main_2.jpg)
3. Find all resize image (example: find pub/media/catalog/product/cache/ -type f -name '*wt09-white_main_2.jpg')
4. Should create only resize image with hash 2765542505660baab28ecd555e27366e

Taken from the upstream pull request.

Code match per tag

Each tag was checked with git apply --check against that tag's files. A clean match means the change applies; it is not a test result. Tags that already contain the fix are marked.

LineCode match per tagTests
2.4.6
2.4.6 conflict 2.4.6-p1 conflict 2.4.6-p2 conflict 2.4.6-p3 conflict 2.4.6-p4 conflict 2.4.6-p5 conflict 2.4.6-p6 conflict 2.4.6-p7 conflict 2.4.6-p8 conflict 2.4.6-p9 conflict 2.4.6-p10 conflict 2.4.6-p11 conflict 2.4.6-p12 conflict 2.4.6-p13 conflict 2.4.6-p14 conflict 2.4.6-p15 conflict
2.4.6: no test data 2.4.6-p1: no test data 2.4.6-p2: no test data 2.4.6-p3: no test data 2.4.6-p4: no test data 2.4.6-p5: no test data 2.4.6-p6: no test data 2.4.6-p7: no test data 2.4.6-p8: no test data 2.4.6-p9: no test data 2.4.6-p10: no test data 2.4.6-p11: no test data 2.4.6-p12: no test data 2.4.6-p13: no test data 2.4.6-p14: no test data 2.4.6-p15: no test data
2.4.7
2.4.7 conflict 2.4.7-p1 conflict 2.4.7-p2 conflict 2.4.7-p3 conflict 2.4.7-p4 conflict 2.4.7-p5 conflict 2.4.7-p6 conflict 2.4.7-p7 conflict 2.4.7-p8 conflict 2.4.7-p9 conflict 2.4.7-p10 conflict
2.4.7: no test data 2.4.7-p1: no test data 2.4.7-p2: no test data 2.4.7-p3: no test data 2.4.7-p4: no test data 2.4.7-p5: no test data 2.4.7-p6: no test data 2.4.7-p7: no test data 2.4.7-p8: no test data 2.4.7-p9: no test data 2.4.7-p10: no test data
2.4.8
2.4.8 conflict 2.4.8-p1 conflict 2.4.8-p2 conflict 2.4.8-p3 conflict 2.4.8-p4 conflict 2.4.8-p5 conflict
2.4.8: no test data 2.4.8-p1: no test data 2.4.8-p2: no test data 2.4.8-p3: no test data 2.4.8-p4: no test data 2.4.8-p5: no test data
2.4.9
2.4.9 clean
2.4.9: fails before, passes afterunit: fails before, passes after

Triage

Model @cf/cloudflare/clef. Probability this is a bug fix: 10.5%. Probability it is security relevant: 0.8%.

Show the model's answers and probabilities
QuestionAnswerProbabilitiesConfidence
Change kindrefactorrefactor 48.0%, bugfix 36.8%, feature 10.6%, tests_only 3.0%, dependency 0.9%, docs_only 0.8%25.4%
Areaframeworkframework 28.2%, other 27.0%, catalog 25.1%13.1%
Reported versionunspecifiedunspecified 20.4%, 2.4.6 3.7%, 2.4.6-p1 2.5%4.0%
Scope1.08 of 21 46.2%, 2 31.1%, 0 22.7%4.3%
Risk0.59 of 21 51.7%, 0 44.6%, 2 3.8%20.0%
Worth backporting1.24 of 22 44.0%, 1 35.9%, 0 20.2%4.4%

Download

For cweagans/composer-patches, choose a version below and download the bundle. Copy its magento2-40388/ folder into patches/composer/, merge composer.patches.json into composer.json, then run composer install. Test files are always removed; paths are relative to each package root, using the default -p1 level.

Packages (1): magento/module-media-storage
Bundle README (what the ZIP ships)
# magento2-40388

Community fix merged upstream into magento/magento2, adapted by magento.watch.
This is not a patch published by Adobe.

Pull request: https://github.com/magento/magento2/pull/40388
Issue: https://github.com/magento/magento2/issues/40399
Author: @rogerdz
Source commit: 0436e467895eba23d310c3c4cee0594e17137d95
Modifications: test files and documentation removed, paths rewritten relative to each Composer package.
Licence: OSL-3.0 / AFL-3.0, as the original Magento Open Source code.
Maintainer: Łukasz Bajsarowicz (@lbajsarowicz)

Licence: Magento Open Source code under OSL-3.0 and AFL-3.0. The bundle carries the original author, source commit and the list of modifications.

Sources

Łukasz Bajsarowicz
Built by

Łukasz Bajsarowicz, e-commerce architect

Magento and Adobe Commerce architecture, upgrades, performance and audits for merchants and agencies since 2015; magento.watch is the tooling I use on those projects.

Open source, maintained on weekends.