ACSD-51857: Slow cron job of aggregate_sales_report_bestsellers_data affects performance

The ACSD-51857 patch fixes the issue where slow cron job aggregate_sales_report_bestsellers_data affects large sales_order and sales_order_item database tables. This patch is available when the Quality Patches Tool (QPT) 1.1.34 is installed. The patch ID is ACSD-51857. Please note that the issue was 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.3-p2

Compatible with Adobe Commerce versions:

  • Adobe Commerce (all deployment methods) 2.4.0 - 2.4.6-p2
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

Cron job performance of aggregate_sales_report_bestsellers_data is slow on sales_order and sales_order_item database tables.

To resolve this, the main data query that grabs data for the report has been re-written to a more efficient form. It now uses a sub-query to determine data subset.

In order for the sub-query to function as fast as possible, a new index was added for the sales_order database table: SALES_ORDER_STORE_STATE_CREATED based on store_id, state, and created_at columns.

Prerequisites

Ensure a large number of orders daily.

Steps to reproduce

  1. Execute the aggregate_sales_report_bestsellers_data cron job.
  2. Check the data to be displayed in the Admin dashboard, under the Bestsellers tab.

Expected results:

Quantity per source under the Configuration tab shouldn’t be empty.

Actual results:

Quantity per source under the Configuration tab is empty.

Apply the patch

To apply individual patches, use the following links depending on your deployment method:

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