-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Slow configurable product attribute option loading #38344
Comments
Hi @abdel-aouby. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hello @abdel-aouby |
Hi @engcom-November. Thank you for working on this issue.
|
Hello @abdel-aouby, Thank you for the report and collaboration! Verified this issue on 2.4-develop.
Hence issue can be confirmed. Thank you. |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-10831 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-November. Thank you for verifying the issue. |
I want to argue regarding the proposed solution because this approach has another performance degradation issue #38934 related to not optimized Also, please keep in mind that |
I can confirm this solution improved performance for a store that has very large numbers of attribute options (1000+ or more) for configurables. |
Summary
When adding configurable products to the cart. it is loading all attribute options regardless if they are product attributes or not. then it is filtering them in a cycle. this is a super slow DB query if you have many options in every attribute.
the query that is used is
this is coming from the method
loadOption
which is called in the collection method_afterLoad
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::_afterLoad
down the investigation, I noticed that this was the case (loading only specific options) until 2015 when it was changed here
e3cecaf#diff-c249eb28ea2a6ea127a89163935e65daea074ebe64b9cd895fa791168b5e7e03R256-R283
any reason for this change?
This is called at least 5 times when using AddProductToCart graphQl request on a configurable product. resulting in a significant performance issue when the configurable product has attributes with thousands of options
Examples
Down the stack trace of the method
loadOptions()
that is called in_afterLoad()
we can see.\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::_afterLoad
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::loadOptions
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::getAttributeOptions
\Magento\ConfigurableProduct\Model\AttributeOptionProvider::getAttributeOptions
In the method
getAttributeOptions(AbstractAttribute $superAttribute, $productId)
there is a call for
getAllOptions(false);
which is loading all attribute options, then down is a foreach loop
foreach ($data as $key => $value)
and inside we are looping the $data and taking/selecting only the options that match
$value['value_index']
ignoring the rest of options that are all loaded. because they are not needed at firstmy solution would be to initially not call
getAllOptions(false);
and use values of the index$value['value_index']
to load only necessary options. using
$superAttribute->getSource()->getSpecificOptions(array_unique($attributeValues));
$attributeValues will be the values of
value_index
from the array $data. which could be retrieved using a combination ofarray_search
array_column
or a classic loop on$data
Proposed solution
Release note
No response
Triage and priority
The text was updated successfully, but these errors were encountered: