Skip to content

Conversation

tdgroot
Copy link
Member

@tdgroot tdgroot commented May 24, 2019

  • Only resize images that are actually in use.
  • Improve code on several places

Description (*)

The resizer uses table catalog_product_entity_media_gallery as source table. These records contain the paths to the actual images. The problem is, these records can exist, even when they are not being used by any products. I added an inner join to table catalog_product_entity_media_gallery_value, to make sure that there's a link between the image and a product.

This improves performance and is less error prone, because the orphan images might not have a physical presence on the filesystem. Now the latter is an other issue, but hardening the resizer won't do any harm.

Fixed Issues

  1. N/a

Manual testing scenarios (*)

  1. Create product with image.
  2. Insert a dummy row into catalog_product_entity_media_gallery.
  3. Run bin/magento catalog:images:resize.
  4. Output should look like this:
Product images resized successfully

1/1 [============================] 100% < 1 sec 44.2 MiB 	| /t/e/testupload.jpg

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

- Only resize images that are actually in use.
- Improve code on several places
@m2-assistant
Copy link

m2-assistant bot commented May 24, 2019

Hi @tdgroot. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

Copy link
Contributor

@dmytro-ch dmytro-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tdgroot,
thank you for your contribution!

Could you please also check and fix the automated tests failures.

) {
parent::__construct();
$this->resize = $resize;
$this->appState = $appState;
$this->objectManager = $objectManager;
$this->progressBarFactory = $progressBarFactory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, according to the Contribution Guide, we may not remove constructor params.
The new constructor parameters should be optional in order to avoid backward compatibility issues.
Please check the Contribution Guide (section Adding a constructor parameter) for more details.

To preserve the constructor signature:

  • Remove type hinting for unused parameters to remove dependency on their type.
  • Add @SuppressWarnings(PHPMD.UnusedFormalParameter) for unused parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review! I updated the changeset, fixed coding style errors and fixed the BIC.

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-5173 has been created to process this Pull Request

@soleksii
Copy link

✔️ QA Passed

Steps to reproduce:

  1. Create product with image;
  2. Insert a dummy row into catalog_product_entity_media_gallery;
  3. Run bin/magento catalog:images:resize

Before:

before1

After:

after1

Note: I unassigned the issue #22808 because PR changes do not fix this problem!

Thanks!

@ghost ghost added the Progress: accept label May 29, 2019
@magento-engcom-team magento-engcom-team merged commit 7d1e34e into magento:2.3-develop Jun 13, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jun 13, 2019

Hi @tdgroot, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants