magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Consider adding a unique key to catalog_product_entity_media_gallery_value

Open Nuranto opened this issue 2 years ago • 1 comments

Summary (*)

Magento 2.4.5

I'm currently inspecting performances and I found this : Capture d’écran 2022-09-23 à 18 51 04

Which leads to a loading time of 40 seconds for a product page, caused by Magento\Catalog\Model\Product\Gallery\ReadHandler::sortMediaEntriesByPosition.

The issue is that for some reason I cannot explain at the moment, I have duplicated content in my catalog_product_entity_media_gallery_value table :
Capture d’écran 2022-09-23 à 18 52 54

It is probably from a third-part extension, or maybe data-migration-tools, but the thing is that should not be allowed.

Proposed solution

=> We should transform CAT_PRD_ENTT_MDA_GLR_VAL_ENTT_ID_VAL_ID_STORE_ID index into a unique index.

Additional Informations

I don't know why this usort exists, since a sort is already made in the SQL query.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users with no workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [X] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Nuranto avatar Sep 23 '22 16:09 Nuranto

Hi @Nuranto. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

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

m2-assistant[bot] avatar Sep 23 '22 16:09 m2-assistant[bot]

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Oct 04 '22 06:10 m2-assistant[bot]

hi @Nuranto , Thank you for reporting and collaboration. If the issue is caused due to 3rd party extension, community cannot able to provide fix for it in this repository as code of that extension is not part of https://github.com/magento/magento2 git repository. All questions, issue reports and fix for them should be addressed to the corresponding extension owners(support) on the Magento Market place page If the issue is from data-migration-tools, it should be reported in this repository Can you please recheck and elaborate the steps / configuration details to reproduce the issue on Magento 2.4-develop instance. Thank you.

engcom-November avatar Oct 04 '22 11:10 engcom-November

Hi @engcom-November,

I was not asking to fix my bug, it's already fixed. I just spotted out a missing unique index, and was explaining the context of that discovery. There's no need to reproduce anything, it's just obvious that this table should have that unique index. It would make the whole project more stable to use, and would avoid bugs to occurs from custom code because of it.

Here's the requested change :

--- a/etc/db_schema.xml	2022-07-21 08:45:08.000000000 +0200
+++ b/etc/db_schema.xml	2022-09-23 19:27:07.000000000 +0200
@@ -863,11 +863,11 @@
         <index referenceId="CATALOG_PRODUCT_ENTITY_MEDIA_GALLERY_VALUE_VALUE_ID" indexType="btree">
             <column name="value_id"/>
         </index>
-        <index referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_ENTT_ID_VAL_ID_STORE_ID" indexType="btree">
+        <constraint referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_ENTT_ID_VAL_ID_STORE_ID_UNQ" xsi:type="unique">
             <column name="entity_id"/>
             <column name="value_id"/>
             <column name="store_id"/>
-        </index>
+        </constraint>
     </table>
     <table name="catalog_product_option" resource="default" engine="innodb" comment="Catalog Product Option Table">
         <column xsi:type="int" name="option_id" unsigned="true" nullable="false" identity="true"

Nuranto avatar Oct 04 '22 12:10 Nuranto

Thank you for the response @Nuranto. We are considering this as Feature request as it is an existing behavior of Magento.

engcom-November avatar Oct 06 '22 12:10 engcom-November