Skip to content
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

Open
1 of 5 tasks
abdel-aouby opened this issue Jan 10, 2024 · 8 comments
Open
1 of 5 tasks

Slow configurable product attribute option loading #38344

abdel-aouby opened this issue Jan 10, 2024 · 8 comments
Labels
Area: Cart & Checkout Component: Attributes Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for dev Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@abdel-aouby
Copy link

abdel-aouby commented Jan 10, 2024

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

SELECT `main_table`.*, `tdv`.`value` AS `default_value`, `tsv`.`value` AS `store_default_value`, IF(tsv.value_id > ?, 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 = ?
WHERE (`main_table`.`attribute_id` = ?) AND (tdv.store_id = ?) ORDER BY main_table.sort_order ASC, value ASC

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.

  1. \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::_afterLoad
  2. \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::loadOptions
  3. \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::getAttributeOptions
  4. \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 first

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));

$attributeValues will be the values of value_index from the array $data. which could be retrieved using a combination of array_search array_column or a classic loop on $data

Proposed solution

-  $options = $superAttribute->getSource()->getAllOptions(false);
+ $optionIds = [];
+ foreach ($data as $key => $value) {
+       $optionIds[] = $value['value_index'];
+ }

+ $options = $superAttribute->getSource()->getSpecificOptions(array_unique($optionIds), false);

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”.
@abdel-aouby abdel-aouby added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Jan 10, 2024
Copy link

m2-assistant bot commented Jan 10, 2024

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:


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 added the Reported on 2.4.x Indicates original Magento version for the Issue report. label Jan 10, 2024
@andrewbess andrewbess added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jan 10, 2024
@andrewbess
Copy link
Contributor

Hello @abdel-aouby
Thank you for your contribution
I think this is great idea to discuss it with community

@engcom-November engcom-November self-assigned this Jan 11, 2024
Copy link

m2-assistant bot commented Jan 11, 2024

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

  • 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- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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-November
Copy link
Contributor

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.

@engcom-November engcom-November added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Component: Attributes Area: Cart & Checkout Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jan 11, 2024
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-10831 is successfully created for this GitHub issue.

Copy link

m2-assistant bot commented Jan 11, 2024

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

@martin-cod
Copy link

martin-cod commented Jul 15, 2024

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

@evktalo
Copy link
Contributor

evktalo commented Nov 15, 2024

I can confirm this solution improved performance for a store that has very large numbers of attribute options (1000+ or more) for configurables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Cart & Checkout Component: Attributes Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for dev Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

No branches or pull requests

7 participants