ACSD-50858: Improved performance for loading banners’ content
The ACSD-50858 patch fixes a banner performance issue in the cart/checkout page: excessive DB queries and increased page loading time. This patch is available when the Quality Patches Tool (QPT) 1.1.31 is installed. The patch ID is ACSD-50858. Please note that the issue is scheduled to be fixed in Adobe Commerce 2.4.7.
Affected products and versions
The patch is created for Adobe Commerce version:
- Adobe Commerce (all deployment methods) 2.4.5-p1
Compatible with Adobe Commerce versions:
- Adobe Commerce (all deployment methods) 2.4.4 - 2.4.6
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
Banner performance is impacted in the cart/checkout page due to excessive DB queries and increased page loading time.
This was fixed by refactoring the way banners’ contents are loaded, which reduced the number of DB queries by 99.99% and the page loading time by ~99%.
Steps to reproduce:
-
Log in to Admin and create a simple product.
-
Create a customer, either from Admin or from the frontend, and add a shipping address for it.
-
Move banners.php to the
magento_root/pub/
folder. -
Generate banners using the
php pub/banners.php
command. It will generate 10,000 simple banners and 1,000 banners with sales rules. -
Log in to the customer created previously on the frontend.
-
Add the product created previously to the cart.
-
Go to the checkout page (checkout/cart).
-
Monitor the
banner/ajax/load
request loading time:-
Without
bin/magento dev:query-log:enable
-
With
bin/magento dev:query-log:enable
code language-none grep 'magento_banner_content' var/debug/db.log | wc -l
-
Expected results:
Decrease in the number of DB queries for magento_banner_content
and cart/checkout page loading time.
Actual results:
Increase in the number of DB queries for magento_banner_content
and cart/checkout page loading time.
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.
Additional information
banners.php content:
\Banner::class);
$banner->setIsEnabled(
\Magento\Banner\Model\Banner::STATUS_ENABLED
)->setName(
'Test Dynamic Block '.$i
)->setTypes(
''
)->setStoreContents(
[0 => 'Dynamic Block Content '.$i]
)->save();
}
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\SalesRule\Model\Rule $salesRule */
$salesRule = $objectManager->create(\Magento\SalesRule\Model\Rule::class);
$salesRule->setData(
[
'name' => '50% Off ',
'is_active' => 1,
'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID],
'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON,
'conditions' => [
[
'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
'attribute' => 'base_subtotal',
'operator' => '>',
'value' => 0
]
],
'simple_action' => 'by_percent',
'discount_amount' => 50,
'discount_step' => 0,
'stop_rules_processing' => 1,
'website_ids' => [
1
]
]
);
$salesRule->save();
for ($i = 0; $i < 1000; $i++) {
$banner = $objectManager->create(\Magento\Banner\Model\Banner::class);
$banner->setData(
[
'name' => 'Get 50% Off ',
'is_enabled' => \Magento\Banner\Model\Banner::STATUS_ENABLED,
'types' => [], /*Any Banner Type*/
'store_contents' => ['<img src="http://example.com/banner_40_percent_off.png" />'],
'banner_sales_rules' => [$salesRule->getId()],
]
);
$banner->save();
}
Related reading
To learn more about Quality Patches Tool, refer to:
- Quality Patches Tool released: a new tool to self-serve quality patches in the support knowledge base.
- Check if patch is available for your Adobe Commerce issue using Quality Patches Tool in the Quality Patches Tool guide.
For info about other patches available in QPT, refer to Quality Patches Tool: Search for patches in the Quality Patches Tool guide.