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

[Performance] ProductRepository cache issue #38572

Open
1 of 5 tasks
Nuranto opened this issue Apr 3, 2024 · 18 comments · May be fixed by #38632
Open
1 of 5 tasks

[Performance] ProductRepository cache issue #38572

Nuranto opened this issue Apr 3, 2024 · 18 comments · May be fixed by #38632
Assignees
Labels
Area: Performance 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: PR in progress Reported on 2.4.6-p4 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

@Nuranto
Copy link
Contributor

Nuranto commented Apr 3, 2024

Preconditions and environment

  • Magento version 2.4.6-p4

Steps to reproduce

$this->searchCriteriaBuilder->addFilter('entity_id', [1,2], 'in');
$searchCriteria = $this->searchCriteriaBuilder->create();
$this->productRepository->getList($searchCriteria);
  1. $this->productRepository->getById(1);

Expected result

getById method should use cache generated by getList

Actual result

Product with ID 1 is loaded twice. This is because the cache key is generated with storeId = null for getById, but with storeId = 1 (default store) for getList.

(Same thing with get instead of getById)

Additional information

get :

public function get($sku, $editMode = false, $storeId = null, $forceReload = false)
{
$cacheKey = $this->getCacheKey([$editMode, $storeId === null ? $storeId : (int) $storeId]);

getById :

public function getById($productId, $editMode = false, $storeId = null, $forceReload = false)
{
$cacheKey = $this->getCacheKey([$editMode, $storeId]);

getList :

foreach ($collection->getItems() as $product) {
$this->cacheProduct(
$this->getCacheKey(
[
false,
$product->getStoreId()
]
),
$product
);
}

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”.
Copy link

m2-assistant bot commented Apr 3, 2024

Hi @Nuranto. 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.

Copy link

m2-assistant bot commented Apr 3, 2024

Hi @engcom-Hotel. 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-Hotel engcom-Hotel added Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Reported on 2.4.6-p4 Indicates original Magento version for the Issue report. labels Apr 3, 2024
@engcom-Hotel
Copy link
Contributor

Hello @Nuranto,

Thanks for the report and collaboration!

We have tried to reproduce the issue in the latest development branch i.e. 2.4-develop and we are able to reproduce the issue.

There are 2 cache keys have been generated for 2 calls below:
First Call

$this->searchCriteriaBuilder->addFilter('entity_id', [1], 'in');
$searchCriteria = $this->searchCriteriaBuilder->create();
$this->productRepository->getList($searchCriteria);

Second Call

$this->productRepository->getById(1);

We have made a custom module to reproduce the issue. Please find attached the same for the reference:

Magz.zip

Hence confirming the issue.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Area: Performance and removed Issue: ready for confirmation labels Apr 3, 2024
@m2-community-project m2-community-project bot added this to Dev In Progress in High Priority Backlog Apr 3, 2024
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board Apr 3, 2024
@github-jira-sync-bot
Copy link

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

Copy link

m2-assistant bot commented Apr 3, 2024

✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in High Priority Backlog Apr 3, 2024
@digitalrisedorset
Copy link

@magento I am working on this

Copy link

m2-assistant bot commented Apr 15, 2024

Hi @digitalrisedorset! 👋
Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

@digitalrisedorset
Copy link

@magento add to contributors team

Copy link

m2-assistant bot commented Apr 15, 2024

Hi @digitalrisedorset! 👋
Thank you for joining. Please accept team invitation 👉 here 👈 and add your comment one more time.

@digitalrisedorset
Copy link

@magento I am working on this

@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in High Priority Backlog Apr 15, 2024
@digitalrisedorset
Copy link

digitalrisedorset commented Apr 15, 2024

@Nuranto thanks for raising this issue. I have been looking into a fix today. I have a way to ensure the cache is not duplicated and that is possibly a way forward.
However, whilst I test the fix, I realise the issue you have found in fact hides another issue. I will describe the second issue for you to add comment whether I am missing something or not:

observations made during the test phase with this bug investigation

  • the getList method is a search method for the product repository
  • the getById method consists in loading the product using the product factory and the product resource model.

These 2 methods have a fundamental difference I believe:

  • getList can load some extension attributes if a file extension_attributes.xml is created and this file defines some attributes to autoload in the search feature
  • the product load method does not benefit from this mechanism. Instead, the extension attributes have to be aggregated to the product using plugins.

I have on my local (without adding any extension attribute) a situation where both methods loads different attributes.

The screenshot below shows the tier price data for instance are returned when the product load is called whilst the search does not return this data:
Screenshot from 2024-04-15 12-38-44

conclusion from the observation

Because the product data for both methods getList and getById are different, it seems that we do not want the search and the product load to share the same cache hash as it would hide some data that we might need on the product page particularly

I am inclined in the end not to add a fix as we want the cache to be different? I'd agree with you that we have some code that is misleading somewhat at the moment. But the fix we are looking to do would genuinely give side-effects that would be tricky to troubleshoot

@Nuranto
Copy link
Contributor Author

Nuranto commented Apr 15, 2024

I agree with you with the observation.

But in that case, the cache should be totally removed from getList method, because getById/get will use that cache if called with storeId parameter.

So the fix should probably be to remove the foreach from getList method. This will prevent issues for what you described, and also slightly improve performance of getList (probably not significant for most cases though...).

@digitalrisedorset
Copy link

@Nuranto I have made a commit today to remove the cache on the getList method as per your recommendation. With more thoughts on it, I see now that your idea is perfectly relevant to our situation. thanks for your input and apologies for not getting it right away in my head

@digitalrisedorset
Copy link

I added some integration tests for this PR

@MaximGns
Copy link

Please also see #38384

@digitalrisedorset
Copy link

@MaximGns I have added new changes as well as many more tests. Thank you for consolidating this issue

@digitalrisedorset
Copy link

@magento run all tests

@engcom-Hotel
Copy link
Contributor

Hello @digitalrisedorset,

I need to tell you that you need to run the above command to its related PR i.e. #38632

@magento run all tests

Let me run it for you.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Performance 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: PR in progress Reported on 2.4.6-p4 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
High Priority Backlog
  
Pull Request In Progress
Development

Successfully merging a pull request may close this issue.

5 participants