Skip to content

Commit 619d608

Browse files
committed
ACP2E-2457: Large MySQL temporary table are created when executing "aggregate_sales_report_bestsellers_data" cron
- testing solution
1 parent c49e9e6 commit 619d608

File tree

1 file changed

+24
-7
lines changed
  • app/code/Magento/Reports/Model/ResourceModel

1 file changed

+24
-7
lines changed

app/code/Magento/Reports/Model/ResourceModel/Helper.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@
1111
*/
1212
namespace Magento\Reports\Model\ResourceModel;
1313

14+
use Magento\Framework\App\ResourceConnection;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
1417
class Helper extends \Magento\Framework\DB\Helper implements \Magento\Reports\Model\ResourceModel\HelperInterface
1518
{
1619
/**
17-
* @param \Magento\Framework\App\ResourceConnection $resource
20+
* @var StoreManagerInterface
21+
*/
22+
protected StoreManagerInterface $storeManager;
23+
24+
/**
25+
* @param ResourceConnection $resource
26+
* @param StoreManagerInterface $storeManager
1827
* @param string $modulePrefix
1928
*/
20-
public function __construct(\Magento\Framework\App\ResourceConnection $resource, $modulePrefix = 'reports')
21-
{
29+
public function __construct(
30+
ResourceConnection $resource,
31+
StoreManagerInterface $storeManager,
32+
string $modulePrefix = 'reports'
33+
) {
34+
$this->storeManager = $storeManager;
2235
parent::__construct($resource, $modulePrefix);
2336
}
2437

@@ -94,11 +107,15 @@ public function updateReportRatingPos($connection, $type, $column, $mainTable, $
94107
$cols['period'] = $periodCol;
95108
$cols[$column] = 't.' . $column;
96109
$cols['rating_pos'] = 't.rating_pos';
97-
$ratingSelect->from($ratingSubSelect, $cols);
98110

99-
$sql = $ratingSelect->insertFromSelect($aggregationTable, array_keys($cols));
100-
$connection->query("SET @pos = 0, @prevStoreId = -1, @prevPeriod = '0000-00-00'");
101-
$connection->query($sql);
111+
foreach ($this->storeManager->getStores(true) as $store) {
112+
$ratingSubSelect->where('t.store_id = ' . $store->getId());
113+
$ratingSelect->from($ratingSubSelect, $cols);
114+
$sql = $ratingSelect->insertFromSelect($aggregationTable, array_keys($cols));
115+
$connection->query("SET @pos = 0, @prevStoreId = -1, @prevPeriod = '0000-00-00'");
116+
$connection->query($sql);
117+
}
118+
102119
return $this;
103120
}
104121
}

0 commit comments

Comments
 (0)