magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

[GraphQL] products query is very slow if retrieving price of several configurable products #36144

Closed t-heuser closed 2 years ago

t-heuser commented 2 years ago

Preconditions and environment

Steps to reproduce

Execute the following query:

query products {
  products(filter: {category_id: {eq: "YOUR_CATEGORY_ID"}} pageSize: 36) {
    items {
      price_range {
        minimum_price {
          final_price {
            currency
            value
          }
        }
      }
    }
  }
}

Here I'm trying to reveice 36 products of a category. 36 is a standard magento listing size for categories. This query is very slow and takes more than a minute if all/a lot of the products inside the category are rather huge configurable products (more than 200 variants).

Expected result

The query is not taking more than a minute to resolve.

Actual result

The query is taking more than a minute to resolve.

Additional information

The problem only occurs if you try to get anything inside price_range. If you don't request this field the query is fast again. The problem can be found here: https://github.com/magento/magento2/blob/91549b925da128ba79807400f551f2b2d0cfeed9/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Product/Price/Provider.php#L100-L113

Magento iterates through all child products and tries to get the minimum price. This is very slow if done for a lot of configurable products with several child products (same problem applies to getMaximalPrice() .

It would be smart here to use the price from the price index as in the table catalog_product_index_price all the data needed is already stored. Magento does this for it's traditional storefront and uses the indexed data there, in GraphQl unfortunately not which leads to the slowness of requests.

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

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

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.


: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

t-heuser commented 2 years ago

What I did as quick workaround: Created an around plugin that gets the data from the index if present and otherwise executes the slow function. Here is a patch file which includes the fix as a module: fix(graphql)__products_query_is_slow_with_configurable_products.txt

m2-assistant[bot] commented 2 years ago

Hi @engcom-Bravo. 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:

engcom-Bravo commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Bravo, here is your Magento Instance: https://93d31a397d34ec8ad3754240d4e7c422.instances.magento-community.engineering Admin access: https://93d31a397d34ec8ad3754240d4e7c422.instances.magento-community.engineering/admin_f8aa Login: e734f3f7 Password: cd76e8920159

engcom-Bravo commented 2 years ago

Hi @oneserv-heuser,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop branch and 2.4.5 but the issue is not reproducible.We are able to retrieve the price of configurable products within less than a minute.

1.Created 36 configurable products with 200+ variants.

Screenshot 2022-09-21 at 5 33 30 PM Screenshot 2022-09-21 at 5 35 18 PM

Please let us know we miss anything.

Thanks.

t-heuser commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @oneserv-heuser. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @oneserv-heuser, here is your Magento Instance: https://93d31a397d34ec8ad3754240d4e7c422.instances.magento-community.engineering Admin access: https://93d31a397d34ec8ad3754240d4e7c422.instances.magento-community.engineering/admin_e0b4 Login: 256208d4 Password: 9f9b143bed01

t-heuser commented 2 years ago

@engcom-Bravo Sorry, it looks like I need to specify my numbers a little bit more. Please try the same with bigger configs. For example our biggest configurable product has around 1.200 single products. So I guess our biggest category has around 15.000 single products behind it's configurable products in the first 36 products.

Could you please try to reproduct the issue with even bigger configs, thank you.

engcom-Bravo commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Bravo, here is your Magento Instance: https://93d31a397d34ec8ad3754240d4e7c422.instances.magento-community.engineering Admin access: https://93d31a397d34ec8ad3754240d4e7c422.instances.magento-community.engineering/admin_0e39 Login: e9a09e29 Password: 688b5e3875e2

engcom-Bravo commented 2 years ago

Hi @oneserv-heuser,

Thanks for quick update.

Verified the issue on Magento 2.4-develop branch and 2.4.5 and the issue is not reproducible.We are able to retrieve the price of configurable products within less than a minute.

Created a 36 Configurable Product with 10,000+ Variants and assigned it to category.

Screenshot 2022-09-23 at 4 20 07 PM Screenshot 2022-09-23 at 4 22 06 PM Screenshot 2022-09-23 at 4 19 54 PM

Please let us know we miss anything.

Thanks.

engcom-Bravo commented 2 years ago

Hi @oneserv-heuser,

We have noticed that this issue has not been updated for a period of 14 Days.
Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.