Module calculates stock level for each stock location each time, without saving & reusing calculated values.
For example, if you use commerce_stock_enforcement module, which disables add to cart submit button if variation is out of stock, stock checker will load all stock locations and calulate stock levels for each of them in runtime. It can be ok if the store has only one stock location, but causes overhead when it has multiple stock location.
Enable commerce_stock_enforcement module and create multiple (e.g. 10) stock locations.
You will see that speed of page loading is slowing down due to mentioned above calculations while add to cart placeholders are working.
Use separate storage for calculated variation stock level results for all stock locations.
I've made the patch, where i use @keyvalue storage to store calculated stock level results and return them if exists.
So now we have one request per product variation, no matter how many stock locations has the store.
Since we store calculated results for stock levels, we do have correctly invalidate them.
And at this point i'm not sure if i do it in a right way.
The proposed patch implementing this:
StockServiceManager::getStockLevel()
LocalStockUpdater::createTransaction()
StockLevelUpdater::processItem()
So, i thing the invalidation of calculated data could be simplified, any suggestions would be grate.
I'm suggesting this patch to see if this approcah actually usefull and if it is, i could improve some of the weaknesses like using Dependency Injection or improving invalidation logic.
Closed: outdated
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.