Assign/remove source from a product triggers cache clearance request for all grouped prdoucts
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
### Preconditions (*)
1. `magento/module-inventory-cache`
2. Magento 2.4.7-p2
### What is happening?
MSI has this function in place as `around` method. Which gets the product IDs from `inventory_stock_ID` table before and after.
Pay attention to `around` method here.
https://github.com/magento/inventory/blob/790c7ff267be04be6cc57f4502e005bec560a2b3/InventoryCache/Plugin/InventoryIndexer/Indexer/Stock/Strategy/Sync/CacheFlush.php#L51
Then, it also has this function as `after` method to index grouped products, which happens after the above function (around) runs, meaning at this time, the system has already sent all the grouped product IDs to clear the cache.
https://github.com/magento/inventory/blob/790c7ff267be04be6cc57f4502e005bec560a2b3/InventoryGroupedProductIndexer/Plugin/InventoryIndexer/Indexer/Stock/Strategy/Sync/ReindexFullPlugin.php#L43
### Explanation
````
public function aroundExecuteList(Sync $subject, callable $proceed, array $stockIds)
{
$beforeReindexProductIds = $this->getProductIdsByStockIds->execute($stockIds);
//finds 500 products, at this point there are grouped products because after plugin would have run earlier and had added grouped products
$proceed($stockIds);
$afterReindexProductIds = $this->getProductIdsByStockIds->execute($stockIds);
//finds 299 products, at this stage after plugin hasn't run yet, as it is around method
$productIdsForCacheClean = array_diff($beforeReindexProductIds, $afterReindexProductIds);
//diff is 201 -- grouped products (200) and 1 product that actually being reindexed for
if ($productIdsForCacheClean) {
$this->flushCacheByProductIds->execute($productIdsForCacheClean);
//201 grouped products (200) are sent to clear the cache
}
}
````
### What this means?
If I have 200 grouped products in my system, every time a single product's (not related to grouped whatsoever) sources deleted/added, then it will send the cache clear request for this product PLUS that 200 grouped products.
### Steps to reproduce (*)
1. Make sure you have some grouped products
2. Run `bin/magento indexer:reindex inventory`
### Expected result (*)
1. The system should only send impacted products to clear the cache
### Actual result (*)
1. The system sends all the grouped products to clear the cache every time it is indexing.
### Proposed solution:
https://github.com/magento/inventory/pull/3402
Contributor guide
Research direction
Start with InventoryCache/Plugin/InventoryIndexer/Indexer/Stock/Strategy/Sync/CacheFlush.php at the aroundExecuteList method, then inspect InventoryGroupedProductIndexer/Plugin/InventoryIndexer/Indexer/Stock/Strategy/Sync/ReindexFullPlugin.php. Reproduce with grouped products and bin/magento indexer:reindex inventory. Done means only products impacted by the indexing operation are sent for cache clearing, rather than all grouped products.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100