Skip to content

GroupedProductGQL - When loading the child products the load is one-by-one (N+1 vs 1 load - Performance) #39798

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

Open
5 tasks
steven-hoffman-jomashop opened this issue Apr 9, 2025 · 3 comments
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.8 Indicates original Magento version for the Issue report.

Comments

@steven-hoffman-jomashop
Copy link

Preconditions and environment

  • 2.4.7 (Should be in 2.4.8 as well)
  • A grouped product exists with childCount >= 2 (Any number >=5; as a few more to make the N+1 queries more evident is recommended)
  • A products GQL call which include the relevant field
    • Should be close to this: { items { id sku ... on GroupedProduct { items { product { id sku } } } } }

Steps to reproduce

  • Create the grouped product as above
  • Create a GQL query as above
  • Enable query logging
  • Send the GQL query

Expected result

  • 1 query to load the grouped product children
    • (Actually 2 or so; as per normal product collection/list loading)

Actual result

  • N queries

Additional information

Issue appears to have been introduced here: ACPT-1181: reset mutable state after request - app/code/Magento/CatalogGraphQl/Model/Resolver/Product.php

  • You can observe the change from using the 'singleton' version to using the newly created version

  • Changing from the singleton version causes each call to this resolver to load only that one child

    • Where, using the singleton, the deferred nature of the valueFactory with a callback meant that all, (subject to GQL resolution rules), would be set via addProductSku prior to the first one to trigger the callback
    • Then the full list is loaded at once, and each subsequent valueFactory callback to resolve would use the previously loaded data.
  • (Also note, cursory review shows other uses of ProductDataProvider without using the Factory)

  • Going back to a singleton would resolve the performance issue

  • Converting to a 'BatchResolver' would allow the use of the factory and would enable mitigation of the performance issue

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without 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.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Copy link

m2-assistant bot commented Apr 9, 2025

Hi @steven-hoffman-jomashop. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues 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 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.

@engcom-Bravo engcom-Bravo self-assigned this Apr 10, 2025
Copy link

m2-assistant bot commented Apr 10, 2025

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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.

@engcom-Bravo engcom-Bravo added the Reported on 2.4.7 Indicates original Magento version for the Issue report. label Apr 10, 2025
@engcom-Bravo engcom-Bravo added Reported on 2.4.8 Indicates original Magento version for the Issue report. and removed Reported on 2.4.7 Indicates original Magento version for the Issue report. labels Apr 21, 2025
@engcom-Bravo
Copy link
Contributor

Hi @steven-hoffman-jomashop,

Thanks for your reporting and collaboration.

We have tried to reproduce the issue in latest 2.4-develop instance and we are not able to reproduce the issue.Kindly refer the screenshots.

Image

We have followed this document https://developer.adobe.com/commerce/webapi/graphql/schema/products/interfaces/types/grouped/ for retrieving grouped product information we got response with 1 query for A grouped product exists with childCount >= 5

{
  "data": {
    "products": {
      "items": [
        {
          "uid": "MTE=",
          "name": "Group",
          "sku": "Group",
          "__typename": "GroupedProduct",
          "items": [
            {
              "qty": 0,
              "position": 1,
              "product": {
                "sku": "Simple",
                "name": "Simple",
                "__typename": "SimpleProduct",
                "url_key": "simple"
              }
            },
            {
              "qty": 0,
              "position": 2,
              "product": {
                "sku": "C2",
                "name": "C2",
                "__typename": "SimpleProduct",
                "url_key": "c2"
              }
            },
            {
              "qty": 0,
              "position": 3,
              "product": {
                "sku": "Nadia Elements Shell",
                "name": "Nadia Elements Shell",
                "__typename": "SimpleProduct",
                "url_key": "nadia-elements-shell"
              }
            },
            {
              "qty": 0,
              "position": 4,
              "product": {
                "sku": "Vulcan Weightlifting Tank",
                "name": "Vulcan Weightlifting Tank",
                "__typename": "SimpleProduct",
                "url_key": "vulcan-weightlifting-tank"
              }
            },
            {
              "qty": 0,
              "position": 5,
              "product": {
                "sku": "fasffs",
                "name": "fasffs",
                "__typename": "SimpleProduct",
                "url_key": "fasffs"
              }
            },
            {
              "qty": 0,
              "position": 6,
              "product": {
                "sku": "gdwwge",
                "name": "gdwwge",
                "__typename": "SimpleProduct",
                "url_key": "gdwwge"
              }
            }
          ]
        }
      ]
    }
  }
}

Kindly recheck the issue in Latest 2.4-develop instance and elaborate the steps to reproduce if the issue is still reproducible.

Thanks.

@engcom-Bravo engcom-Bravo added the Issue: needs update Additional information is require, waiting for response label May 5, 2025
@github-project-automation github-project-automation bot moved this to Ready for Confirmation in Issue Confirmation and Triage Board May 5, 2025
@ct-prd-projects-boards-automation ct-prd-projects-boards-automation bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.8 Indicates original Magento version for the Issue report.
Projects
Development

No branches or pull requests

2 participants