-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Only resize images for themes which are being used instead of all installed themes. #8142
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
Only resize images for themes which are being used instead of all installed themes. #8142
Conversation
While this will improve current situation, am I correct that there is still possibility to generate images that are never used? Consider scenario where there are two websites (with separate sets of products) with different themes inside single Magento installation. Since both themes are active, images will get generated for both themes even if the product is active only in one website. Ideally we would generate image for themes that are used in websites where the product is active? |
@paveq: correct! This is a first attempt at reducing the amount of generated resized images. But this can be optimized further like you are suggesting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check and fix the case when theme is set in other places than store
$themesInUse = []; | ||
|
||
$registeredThemes = $this->themeCollection->loadRegisteredThemes(); | ||
$storesByThemes = $this->themeCustomizationConfig->getStoresByThemes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Themes can be set not only on store level, but on product/category/cms. Please addthe logic which would include these cases as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hostep please see comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vrann @hostep I've used this code and added themes checking for produt, category and pages.
denisristic@8308ae1#comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vrann Is it actually necessary to check for product/category/page?
Even if any of them have assigned custom theme that is disabled it would not matter because it would not be displayed because theme is disabled?
@vrann I'm not sure if it is even possible performance-wise to get all combinations of per page used themes per product. And even then, these can be easily changed by store admin, so can we ever be sure we pre-generate correct images? I see one alternative way going forward: add a boolean toggle to admin "pre-generate images". Allow people to use old style M1 "on-fly" generation, which is always 100% guaranteed to generate only images that are ever used somewhere. |
@vrann: thanks for the review. Since the changes you request will turn out to be really complicated, I'm no longer going to pursue this myself. |
Closing this PR due to inactivity since Feb 21 |
Currently Magento resizes catalog images in the frontend for all the installed themes.
So if you have the
Magento/blank
,Magento/luma
and your own custom theme, it would resize the images for those three themes. Even if you only use your own custom theme in the frontend.This PR should fix this, it will only resize catalog images for themes which are actually active.
This code is being executed when running the command:
bin/magento catalog:images:resize
and also in theafterSave
method of theMagento\Catalog\Model\Product
class.