Open abdel-aouby opened 7 months ago
Hi @abdel-aouby. 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. 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@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel. :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.
Hello @abdel-aouby Thank you for your contribution I think this is great idea to discuss it with community
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:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. Hello @abdel-aouby,
Thank you for the report and collaboration!
Verified this issue on 2.4-develop. When adding a configurable product to cart, all the attributes are being loaded with the below query, which are not required.
## 77937 ## QUERY
SQL: SELECT `main_table`.*, `tdv`.`value` AS `default_value`, `tsv`.`value` AS `store_default_value`, IF(tsv.value_id > 0, tsv.value, tdv.value) AS `value` FROM `eav_attribute_option` AS `main_table`
INNER JOIN `eav_attribute_option_value` AS `tdv` ON tdv.option_id = main_table.option_id
LEFT JOIN `eav_attribute_option_value` AS `tsv` ON tsv.option_id = main_table.option_id AND tsv.store_id = '1' WHERE (`main_table`.`attribute_id` = '83') AND (tdv.store_id = 0) ORDER BY main_table.sort_order ASC, `value` ASC
Hence issue can be confirmed.
Thank you.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-10831 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
my 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));
I want to argue regarding the proposed solution because this approach has another performance degradation issue #38934 related to not optimized getSpecificOptions
Also, please keep in mind that getSpecificOptions
is a unique method for only class \Magento\Eav\Model\Entity\Attribute\Source\Table
and this is not a public contract method of \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
class or \Magento\Eav\Model\Entity\Attribute\Source\SourceInterface
interface
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
https://github.com/magento/magento2/commit/e3cecafccd999ee3b9ab5df0094dec02c12fad8c#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 forgetAllOptions(false);
which is loading all attribute options, then down is a foreach loopforeach ($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