Skip to content

MC-41852: issue with product image cache #32768

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

Merged
merged 2 commits into from
May 18, 2022
Merged

MC-41852: issue with product image cache #32768

merged 2 commits into from
May 18, 2022

Conversation

temptask
Copy link
Contributor

@temptask temptask commented Apr 15, 2021

Description (*)

This PR fixes issue when product image that contains dot in image name at first or second position (e.g. "i.mage.png") is not showing on frontend after flushing catalog image cache.

This happened because when uploading product image magento uses files dispersion setting and saving image to path generated by \Magento\Framework\File\Uploader::getDispersionPath which consists of two directories defined by two first letters of filename (e.g. path for "image.png" will be /i/m/image.png). But, in case when there is dot in first two letters of filename, directory name with underscore will be used (e.g. path for filename "i.mage.png" will be /i/_/image.png).

When catalog image cache is flushed and frontend product image is requested magento tries to create new cache file in \Magento\MediaStorage\App\Media::createLocalCopy and tries to retrieve original image location by calling \Magento\MediaStorage\App\Media::getOriginalImage.

This function is using regexp to get from path like "media/catalog/product/cache/838ef3af6b51df9f635b7eb110d280c6/i/m/image.png" original image path "/i/m/image.png".
This regexp was changed in 362eba8 from |^.*((?:/[^/]+){3})$| to |^.*?((?:/([^/])/([^/])/\2\3)?/?[^/]+$)|. New regexp (|^.*?((?:/([^/])/([^/])/\2\3)?/?[^/]+$)|) is not taking into consideration cases when original filename contained dot in first two letters and therefore path with underscore instead of dot is generated.

In this PR old regexp (|^.*((?:/[^/]+){3})$|) was restored since its working correctly with all filenames.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes issue with product image cache #32699

Manual testing scenarios (*)

  1. Create a new product or go to the existing one
  2. Add image to product (image name should contain dot in first or second position, e.g. "i.mage.png")
  3. Save product
  4. Go to System -> Cache Management and click button "Flush Catalog Image Cache"
  5. Open product on frontend

Actual result: (before this PR)
Placeholder showed instead of product image

Expected result: (after this PR)
Product image is showed

Questions or comments

Since commit 362eba8 that changed working regexp to not correctly working with all filenames regexp was introduced with "[performance]" text in commit message, it was probably fixing some performance issues of older regexp.
In this PR it was decided not to modify this not fully working regexp but rather restore old one because it was not very clear what performance changes is was making and because of possible risks of introducing new regexp.
So, reviewer probably should take a close look at deleted regexp before accepting this PR.

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Apr 15, 2021

Hi @temptask. Thank you for your contribution
Here are 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added the Priority: P3 May be fixed according to the position in the backlog. label Apr 15, 2021
@mrtuvn mrtuvn added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Apr 16, 2021
@mrtuvn
Copy link
Contributor

mrtuvn commented Apr 16, 2021

Can you cover your changes with automation tests

- Reverted regular expression value to previous state (before performance improvements) to work correctly with all image names
@temptask
Copy link
Contributor Author

@magento run all tests

@mrtuvn
Copy link
Contributor

mrtuvn commented Apr 19, 2021

@magento run Functional Tests CE, Functional Tests B2B

@mrtuvn mrtuvn requested review from duhon and shiftedreality April 19, 2021 11:15
@mrtuvn mrtuvn added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Apr 19, 2021
@magento-engcom-team
Copy link
Contributor

Hi @Den4ik, thank you for the review.
ENGCOM-9095 has been created to process this Pull Request

@Den4ik Den4ik mentioned this pull request Jul 27, 2021
5 tasks
@ihor-sviziev ihor-sviziev added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Mar 8, 2022
@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Mar 8, 2022

Hi @sidolov @sivaschenko,
I changed the priority to P2 because some product images are shown as a default Magento image as if there is no image uploaded. For instance, it also works incorrectly when the image has a dot in the filename (which is quite frequent).

Also, breaks the cases when the path is customized by extensions. There no easy way to fix it, as method is private, so the only way to fix that now - apply patch.

PS: I believe we should cover this replace with some unit tests and add multiple data samples, not just a single MFTF test

@ihor-sviziev ihor-sviziev removed the Priority: P3 May be fixed according to the position in the backlog. label Mar 8, 2022
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-9095 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Preconditions:

  1. Have Magento installed with latest version

Manual testing scenario:

  1. Create a new product in the admin side.

  2. Upload image files to the same product and save it. (Where image file names should be involved with dots as like - a.asd.sads.png, a1.cds22.12.jpeg etc)

  3. Go to System -> Cache Management and click button "Flush Catalog Image Cache"

  4. View the product details page in the front end and validate images are displayed

Before: ✖️ Image were not getting displayed in the product details page.

image

After: ✔️ Images are getting displayed in the product details page.

image

Tried to delete the uploaded files , and tried to replace with new image files as such. No issues noticed. There is no additional testing is required as part of regression since there is MTFT already covered with this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Catalog Component: MediaStorage Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

issue with product image cache
9 participants