Skip to content

Magento 2 mariadb instance overload after cache clean for sales_bestsellers_aggregated tables

Magento 2 version: 2.4.6-p8

Mariadb version : 10.4

I m facing an issue when we launch ‘bin/magento cache:clean‘ on our Magento 2 instance.
Indeed, when the cache clean is launched, our database threads are overloading with one specific query :

Sending data | SELECT DATE_FORMAT(period, '%Y-%m') AS `period`, SUM(qty_ordered) AS `qty_ordered`, `sales_bestsellers_aggregated_monthly`.`product_id`, MAX(product_name) AS `product_name`, MAX(product_price) AS `product_price` FROM `sales_bestsellers_aggregated_monthly` WHERE (rating_pos <= 5) AND (store_id IN(0)) AND (store_id IN(0)) GROUP BY `period`,
        `product_id` ORDER BY `period` ASC, `qty_ordered` DESC

This query is launched on loop, so it saturated mariadb instance and we have to restart the service. We done those purges to reload the Magento 2 front product listing for specific search queries.

Is it normal that Magento 2 make a lot of queries for this specific table after a purge ? Is there way to avoid it ? With my researches, it is probably launched in this file vendor/magento/module-sales/Model/ResourceModel/Report/Bestsellers.php. Can it be caused by a wrong management of Redis cache ?

Thanks,