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
product repository cache does not load the product when storeId is null #38632
base: 2.4-develop
Are you sure you want to change the base?
product repository cache does not load the product when storeId is null #38632
Conversation
…counterproductive effects on the system
…the cache works in the same way as with the getById method
Hi @digitalrisedorset. Thank you for your contribution! Add the comment under your pull request to deploy test or vanilla Magento instance:
❗ Automated tests can be triggered manually with an appropriate comment:
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
…o cover all methods parameters input possibilities
Description (*)
At the current time, the behaviour of the product repository is like below:
The
\Magento\Catalog\Model\ProductRepository::getById
method and the\Magento\Catalog\Model\ProductRepository::getList
method do not share a consistent behaviour regarding thestoreId
fallback value. When the storeId parameter in these 2 method is null, the behaviour is:getList
method uses the method\Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection::getStoreId
to read the store id. This method has a fallback that sets thestoreId
with thestoreManager
storeId
value.getById
method instead leaves thestoreId
unchanged even if the parameter in the method is null.get
method instead leaves thestoreId
unchanged even if the parameter in the method is null.For a same product id and the same default store, this implementation currently triggers 2 different hashes in the product repository local cache.
Yet, in the getById method, when the product factory creates a product object, this sets the store id with the storeManager store id.
As a consequence, although the hash for the cache is different to the getList method for the same product id, the product store is eventually the same and therefore this sets in the cache the same product on 2 separate cache hashes.
The same issue occurs with the
get
method when the storeId is null.The fix is twofold:
getList
method was removedget
andgetById
now sets thestoreId
to the current store if the parameterstoreId
is null so that the cache they use can be sharedThe benefits with the second change is that both
get
andgetById
now share their cache even ifstoreId
is not passedRelated Pull Requests
none
Fixed Issues (if relevant)
none
Manual testing scenarios (*)
Test 1
for a valid product id in the catalog, trigger the search for the product id using the product repository
getList
methodand verify the product is not assigned to a local cache
Test 2
for the same product id as the step above, trigger the product load using the product repository
getById
method and verify the product is assigned to the local cacheTest 3
for the same product as the step above, trigger the product load using the product repository
get
method and verify the product data come from the local cacheTest 4
change the default store in the backend and iterate both steps above and verify the product is loaded as expected and uses only one hash for the local cache
Test 5
Trigger the search for a product using get method on new request and follow with loading the same product using the method
getById
. Verify the product is only loaded onceand the cache used is the one created during the first call with get method
Questions or comments
There is a possible backward compatibility concern to verify: I have removed the lines that set the
storeId
against the product in bothget
andgetById
methods. The reasoning for doing this change is that thestoreId
is set when the productFactory creates the product and with the changes, thestoreId
is now a lot more consistent in terms of type.However, should a core code rely on
storeId
being a string, this change could break some other places.Contribution checklist (*)