Skip to content

#26065 isSaleable cache and optimize result for configurable products #26071

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

Merged
merged 2 commits into from
Feb 7, 2020

Conversation

ilnytskyi
Copy link
Contributor

@ilnytskyi ilnytskyi commented Dec 16, 2019

Description (*)

Improves performance of \Magento\ConfigurableProduct\Model\Product\Type\Configurable::isSalable for multiple calls
Exclude swatches plugin

branch 2.4-develop + demo data
Before
https://user-images.githubusercontent.com/3192770/71307970-9eb7e400-23f6-11ea-86f3-e60951e639da.png

After
https://user-images.githubusercontent.com/3192770/71307989-be4f0c80-23f6-11ea-8081-9abd5539f030.png

Fixed Issues (if relevant)

  1. Performance of isSalable method check on configurable product #26065: isSaleable performance on multiple calls

Manual testing scenarios (*)

  1. Call \Magento\ConfigurableProduct\Model\Product\Type\Configurable::isSalable many times
  2. See steps in Performance of isSalable method check on configurable product #26065

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@ilnytskyi ilnytskyi requested a review from akaplya as a code owner December 16, 2019 19:19
@m2-assistant
Copy link

m2-assistant bot commented Dec 16, 2019

Hi @ilnytskyi. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@@ -585,7 +592,7 @@ protected function getGalleryReadHandler()
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
*/
public function getUsedProductCollection($product)
protected function getLinkedProductCollection($product)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thank you for your contribution. Just a question: what's the reason behind the introduction of this new method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aleron75
as described in #26065

the swatches plugin is not needed Magento\Swatches\Model\Plugin\Configurable::afterGetUsedProductCollection
so isSaleable can call internal method. It slightly improves performance if swatches are disabled on category page (listing page). Before, when the code called isSaleable it was always called afterGetUsedProductCollection that just adds attributes to select, however they are not needed in this check.
It also helps if isSaleable is called a few times in different places

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, @ilnytskyi I didn't explain myself. I got the point of the optimization, I was just wondering why did you introduce the additional getLinkedProductCollection() method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, to avoid code duplication inside isSalable. (collection building)
getUsedProductCollection is used inside isSalable so i decided to use it as wrapper for the collection building then move its logic to the new method. This way
getUsedProductCollection can be used as previously and
getLinkedProductCollection only internal method that is not affected by plugins

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok great, thank you!

@aleron75 aleron75 self-assigned this Jan 24, 2020
@ilnytskyi ilnytskyi requested a review from aleron75 January 24, 2020 09:13
@magento-engcom-team
Copy link
Contributor

Hi @aleron75, thank you for the review.
ENGCOM-6689 has been created to process this Pull Request
✳️ @aleron75, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Before:

\Magento\ConfigurableProduct\Model\Product\Type\Configurable::isSalable - 693 ms

before

After:

\Magento\ConfigurableProduct\Model\Product\Type\Configurable::isSalable - 165 ms

after

@m2-assistant
Copy link

m2-assistant bot commented Feb 7, 2020

Hi @ilnytskyi, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@sdzhepa sdzhepa mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Progress: accept
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants