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
NOTE
The patch might become applicable to other versions with new Quality Patches Tool releases. To check if the patch is compatible with your Adobe Commerce version, update the 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:

  1. Log in to Admin and create a simple product.

  2. Create a customer, either from Admin or from the frontend, and add a shipping address for it.

  3. Move banners.php to the magento_root/pub/ folder.

  4. Generate banners using the php pub/banners.php command. It will generate 10,000 simple banners and 1,000 banners with sales rules.

  5. Log in to the customer created previously on the frontend.

  6. Add the product created previously to the cart.

  7. Go to the checkout page (checkout/cart).

  8. 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:

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();
}

To learn more about Quality Patches Tool, refer to:

For info about other patches available in QPT, refer to Quality Patches Tool: Search for patches in the Quality Patches Tool guide.

recommendation-more-help
c2d96e17-5179-455c-ad3a-e1697bb4e8c3