ACSD-67166: Duplicate execution of the cataloginventory_stock_status query when loading a quote on the storefront
        
        
        
        The ACSD-67166 patch fixes the issue where duplicate execution of the cataloginventory_stock_status query occurs when loading a quote on the storefront, causing redundant DB calls. This patch is available when the Quality Patches Tool (QPT) 1.1.70 is installed. The patch ID is ACSD-67166. Please note that this issue is scheduled to be fixed in Adobe Commerce 2.4.9.
Affected products and versions
The patch is created for Adobe Commerce version:
- Adobe Commerce (all deployment methods) 2.4.5-p13
 
Compatible with Adobe Commerce versions:
- Adobe Commerce (all deployment methods) 2.4.4 - 2.4.8-p2
 
magento/quality-patches package to the latest version and check the compatibility on the Quality Patches Tool: Search for patches page. Use the patch ID as a search keyword to locate the patch.Issue
Duplicate execution of the cataloginventory_stock_status query occurs when loading a quote on the storefront, causing redundant DB calls.
Steps to reproduce:
- 
                  
Install a clean instance.
 - 
                  
Create a Category and a Simple Product.
 - 
                  
Go to the category and add a product to the cart.
 - 
                  
Go to the cart page:
/checkout/cart/ - 
                  
Set breakpoints in xDebug:
app/code/Magento/CatalogInventory/Model/StockRegistryPreloader.php:115app/code/Magento/InventoryCatalog/Model/LegacyStockStatusCache.php:73lib/internal/Magento/Framework/Data/AbstractSearchResult.php:233- Breakpoint Condition: 
strpos($this->query->getSelectSql(true), 'stock_status') !==false
Add$_SERVER['REQUEST_URI']to watches in PHPStorm to verify the query is called twice within the same request. 
 
Expected results:
The query is executed once per request.
Actual results:
The same query is executed twice:
SELECT `main_table`.*, `cp_table`.`sku`, `cp_table`.`type_id` FROM `cataloginventory_stock_status` AS `main_table`
 INNER JOIN `catalog_product_entity` AS `cp_table` ON main_table.product_id = cp_table.entity_id AND (cp_table.created_in <= 1 AND cp_table.updated_in > 1) WHERE (`main_table`.`product_id` IN(2)) AND (`main_table`.`website_id` = '0')
            Apply the patch
To apply individual patches, use the following links depending on your deployment method:
- Adobe Commerce or Magento Open Source on-premises: Quality Patches Tool > Usage in the Quality Patches Tool guide
 - Adobe Commerce on cloud infrastructure: Upgrades and Patches > Apply Patches in the Commerce on Cloud Infrastructure guide
 
Related reading
To learn more about Quality Patches Tool, refer to:
- Quality Patches Tool: A self-service tool for quality patches in the Tools guide