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

Cache IsProductAssignedToStock service to improve cart performance #2692

Merged
merged 5 commits into from
Nov 9, 2019

Conversation

sky-hub
Copy link
Member

@sky-hub sky-hub commented Nov 7, 2019

Description (*)

While in cart or checkout page a large number of database queries are performed to check if a product is assigned to a specific stockId. Queries are correlated with the number of products in cart, more products, more queries for same product. The issue is manifested while Magento_Inventory module is enabled.
Tested on Magento Open Source 2.3.1

Query is: select stock_source_link.* from inventory_source_stock_link as stock_source_link join inventory_source_item on inventory_source_item.source_code = stock_source_link.source_code where (stock_source_link.stock_id = ?) and (inventory_source_item.sku = ?)

Fixed Issues (if relevant)

  1. [Performance]Magento 2.3 Performance issue because of huge amount of mysql queries per products in cart #2496

Manual testing scenarios (*)

  1. Add one product to cart
  2. Navigate to checkout and check number of mysql requests in blackfire or any developer toolbar
  3. Add another product to cart
  4. Navigate to checkout/cart and compare number of mysql requests in blackfire or any developer toolbar

Questions or comments

N/A

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)

@sky-hub sky-hub self-assigned this Nov 7, 2019
@m2-community-project
Copy link

@sky-hub unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

@ishakhsuvarov
Copy link
Contributor

Hi @sky-hub

Thank you for the PR! I've got a couple of questions regarding this.

  • Do you have any numbers with regards to optimized queries?
  • Have you tested this only on default stock/source combination or with multiple stocks as well?

@sky-hub
Copy link
Member Author

sky-hub commented Nov 8, 2019

  1. For two products in cart there are 18 queries and goes up for each added product.
  2. Issue was tested only with sources. "Default Stock" is not assigned to products.

Note: If you would like to have a cache service injected in current interceptor instead of caching in interceptor, please let me know and i will update accordingly.

@ishakhsuvarov
Copy link
Contributor

@sky-hub Current approach seems ok to me. Thanks for the numbers, appreciate your efforts.

I'll merge it once again with 2.3-develop to make sure it's good to go together with other set of patches and get it delivered shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants