magento2: indexer_update_all_views invalidates all cache after any inventory stock change
Preconditions and environment
- Magento version: 2.4.5-p1
- Both on FPC and Varnish
- Indexers update on schedule (cron)
- Inventory with only
defaultsource and stock - 2 websites, 3 stores (only 2 stores enabled)
- Flat category: Yes
- Flat products: No
- Decrease Stock When Order is Placed: Yes
- Set Items’ Status to be In Stock When Order is Cancelled: Yes
- Display Out of Stock Products: Yes
- Only X left Threshold: 0
- Display Products Availability in Stock on Storefront: Yes
- Synchronize with Catalog: Yes
- Manage Stock: Yes
- Manage Stock: No Backorers
- Out-of-Stock Threshold: 0
- Automatically Return Credit Memo Item to Stock: No
If that counts, this system was upgraded from Magento 1.9.4 to 2.4.3 and later every version.
After stock changes, the indexer_update_all_views invalidates all cache with “invalidateInfo”:{“tags”:[],“mode”:“all”}}.
Issue appears when creating a shipment or updating the inventory in a module with the following code:
$sourceItem = $this->sourceItemFactory->create();
$sourceItem->setSourceCode('default');
$sourceItem->setSku($sku);
$sourceItem->setQuantity($qtyToSet);
$sourceItem->setStatus(($qty > 0 ? 1 : 0));
$this->sourceItemsSaveInterface->execute([$sourceItem]);
The invalidation happens the next cron run inside indexer_update_all_views .
Possibly they have the same issue in the new comments (since 2022 Q3) on an already closed bug report: https://github.com/magento/magento2/issues/30128#issuecomment-1275090668
Due to it happens for others too, I think it is a core issue, but possibly we have the same 3rd party modules installed. I tried to check all of these modules for any cache related code, but could not find anything that could cause.
3rd party modules:
Amasty_Base
Amasty_CronScheduleList
Amasty_Finder
Amasty_Geoip
Amasty_GdprCookie
Amasty_GdprLite
Amasty_GdprFrontendUi
Amasty_Mage245Fix
Amasty_Mage24Fix
Amasty_SeoSingleUrl
BrunoCanada_HrefLang
Chessio_Matomo
Codazon_AjaxLayeredNavPro
Codazon_Core
Codazon_GoogleAmpManager
Codazon_Lookbookpro
Codazon_MegaMenu
Codazon_ProductFilter
Codazon_ProductLabel
Codazon_QuickShop
Codazon_SalesPro
Codazon_ShippingCostCalculator
Codazon_Shopbybrandpro
Codazon_ShoppingCartPro
Codazon_ThemeLayoutPro
Dan0sz_ResourceHints
Flurrybox_Core
Flurrybox_EnhancedPrivacy
Genaker_ValidateAttributeLength
GhoSter_OutOfStockAtLast
Iazel_RegenProductUrl
Lillik_PriceDecimal
M2Boilerplate_CriticalCss
MageSuite_Magepack
MageWorx_SearchSuiteAutocomplete
Magefan_Community
Magefan_Blog
Magefan_BlogGraphQl
Magefan_WysiwygAdvanced
Magefox_GoogleShopping
Magenest_CacheWarmer
Yireo_LinkPreload
Yireo_NextGenImages
Yireo_Webp2
Steps to reproduce
- Create a shipment for an order / update the stock programmatically
- Wait for the next cron run
- Check page headers/waiting time
- Verify the issue in debug.log
Expected result
Invalidate cache only for the changed products and their categories.
Actual result
Something issues cache invalidation {“tags”:[],“mode”:“all”}} 4 times significantly earlier (2 sec!) before proceeding to product and category invalidation.
Then the cache misses, and the page takes 2+ seconds to respond, that leads to bad page speed ratings at google and losing customers.
Additional information
FPC log:
[2023-02-07T09:42:06.090008+00:00] main.INFO: Cron Job magenest_cachewarmer_warm is successfully finished. Statistics: {"sum":0.0032229423522949,"count":1,"realmem":0,"emalloc":144304,"realmem_start":206045184,"emalloc_start":191280120} [] []
[2023-02-07T09:42:06.196229+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T09:42:06.236829+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T09:42:06.237366+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T09:42:06.237529+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T09:42:08.182239+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_p_7913","FPC"],"mode":"matchingTag"}} []
[2023-02-07T09:42:08.231403+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_p_7728","FPC"],"mode":"matchingTag"}} []
[2023-02-07T09:42:08.278293+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_c_p_7","FPC"],"mode":"matchingTag"}} []
[2023-02-07T09:42:08.328399+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_c_2","FPC"],"mode":"matchingTag"}} []
[2023-02-07T09:42:08.379839+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_c_7","FPC"],"mode":"matchingTag"}} []
[2023-02-07T09:42:08.381348+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_p_7913","cat_p_7728","cat_c_p_7","cat_c_2","cat_c_7"],"mode":"matchingAnyTag"}} []
[2023-02-07T09:42:08.381696+00:00] main.INFO: Cron Job indexer_update_all_views is successfully finished. Statistics: {"sum":2.4353058338165,"count":1,"realmem":20971520,"emalloc":27873416,"realmem_start":206045184,"emalloc_start":191825056} [] []
Varnish log:
[2023-02-07T10:44:05.332559+00:00] main.INFO: Cron Job indexer_update_all_views is run [] []
[2023-02-07T10:44:06.129578+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T10:44:06.196482+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T10:44:06.196830+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T10:44:06.197018+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"}} []
[2023-02-07T10:44:07.557597+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"servers":[{"Laminas\\Uri\\Uri":"http://127.0.0.1:6081/"}],"formattedTagsChunk":"((^|,)cat_p_6771(,|$))|((^|,)cat_p_6982(,|$))|((^|,)cat_c_2(,|$))|((^|,)cat_c_7(,|$))|((^|,)cat_c_p_7(,|$))"}} []
[2023-02-07T10:44:07.558501+00:00] main.DEBUG: cache_invalidate: {"method":"GET","url":"http:/","invalidateInfo":{"tags":["cat_p_6771","cat_p_6982","cat_c_2","cat_c_7","cat_c_p_7"],"mode":"matchingAnyTag"}} []
[2023-02-07T10:44:07.558759+00:00] main.INFO: Cron Job indexer_update_all_views is successfully finished. Statistics: {"sum":2.2261419296265,"count":1,"realmem":10485760,"emalloc":22727128,"realmem_start":206045184,"emalloc_start":191820112} [] []
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”.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (1 by maintainers)
This was resolved in 2.4.6 by this commit https://github.com/magento/inventory/commit/b6d7223b8ca3b13c4049b3b0f6efc645b0848e01
@mortenbirkelund I have rewritten my price/stock updater with REST API calls, now everything works well and also it is faster. I guess this is the preferred/better supported method for the future.