Skip to content

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

Open
@steven-hoffman-jomashop

Description

@steven-hoffman-jomashop

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”.

Metadata

Metadata

Assignees

Labels

Issue: needs updateAdditional information is require, waiting for responseReported on 2.4.8Indicates original Magento version for the Issue report.

Type

No type

Projects

Status

Needs Update

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions