Skip to content

Commit 71bca16

Browse files
committed
ACP2E-1961: Cron job aggregate_sales_report_bestsellers_data is slow and affects on performance
- adjusted report query
1 parent 2c815a9 commit 71bca16

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

app/code/Magento/Sales/Model/ResourceModel/Report/Bestsellers.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public function aggregate($from = null, $to = null)
119119
{
120120
$connection = $this->getConnection();
121121
$this->clearByDateRange($from, $to);
122-
123122
foreach ($this->storeManager->getStores(true) as $store) {
124123
$this->processStoreAggregate($store->getId(), $from, $to);
125124
}
@@ -200,13 +199,13 @@ protected function getRangeSubSelect($from = null, $to = null): ?Select
200199
/**
201200
* Calculate report aggregate per store
202201
*
203-
* @param int $storeId
202+
* @param int|null $storeId
204203
* @param string|int|\DateTime|array|null $from
205204
* @param string|int|\DateTime|array|null $to
206205
* @return void
207206
* @throws LocalizedException
208207
*/
209-
protected function processStoreAggregate(int $storeId, $from = null, $to = null): void
208+
protected function processStoreAggregate(?int $storeId, $from = null, $to = null): void
210209
{
211210
$connection = $this->getConnection();
212211

@@ -248,11 +247,10 @@ protected function processStoreAggregate(int $storeId, $from = null, $to = null)
248247
'order_item.parent_item_id = order_item_parent.item_id',
249248
[]
250249
)->where(
251-
'source_table.entity_id IN (?)',
252-
"SELECT entity_id FROM " . $this->getTable('sales_order') .
250+
"source_table.entity_id IN (SELECT entity_id FROM " . $this->getTable('sales_order') .
253251
" WHERE store_id = " . $storeId .
254252
" AND state != '" . \Magento\Sales\Model\Order::STATE_CANCELED . "'" .
255-
($subSelect !== null ? " AND " . $this->_makeConditionFromDateRangeSelect($subSelect, $periodExpr) : '')
253+
($subSelect !== null ? " AND " . $this->_makeConditionFromDateRangeSelect($subSelect, $periodExpr) : '') . ")"
256254
)->where(
257255
'order_item.product_type NOT IN(?)',
258256
$this->ignoredProductTypes

0 commit comments

Comments
 (0)