Skip to content

Commit e12037e

Browse files
committed
MC-42025: Bad performance and outages after upgrade to MariaDB 10.2.34
1 parent 4db70dd commit e12037e

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

app/code/Magento/Sales/Model/Grid/LastUpdateTimeCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LastUpdateTimeCache
1717
/**
1818
* Prefix for cache key.
1919
*/
20-
private const CACHE_PREFIX = 'LAST_GRID_UPDATE_TIME';
20+
private const CACHE_PREFIX = 'LAST_GRID_UPDATE_TIME:';
2121

2222
/**
2323
* @var CacheInterface

app/code/Magento/Sales/Model/ResourceModel/Grid.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ public function refreshBySchedule()
140140
array_keys($this->columns)
141141
);
142142

143-
$lastUpdatedAt = max(array_column($fetchResult, 'updated_at'));
143+
$timestamps = array_column($fetchResult, 'updated_at');
144+
if ($timestamps) {
145+
$lastUpdatedAt = max(max($timestamps), $lastUpdatedAt);
146+
}
144147
}
145148

146149
if ($lastUpdatedAt) {

app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedAtListProvider.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,17 @@ public function __construct(
4949
*/
5050
public function getIds($mainTableName, $gridTableName)
5151
{
52-
$mainTableName = $this->resourceConnection->getTableName($mainTableName);
53-
$gridTableName = $this->resourceConnection->getTableName($gridTableName);
5452
$select = $this->connection->select()
55-
->from($mainTableName, [$mainTableName . '.entity_id'])
53+
->from(['main_table' => $this->resourceConnection->getTableName($mainTableName)], ['main_table.entity_id'])
5654
->joinInner(
57-
[$gridTableName => $gridTableName],
58-
sprintf(
59-
'%s.entity_id = %s.entity_id AND %s.updated_at > %s.updated_at',
60-
$mainTableName,
61-
$gridTableName,
62-
$mainTableName,
63-
$gridTableName
64-
),
55+
['grid_table' => $this->resourceConnection->getTableName($gridTableName)],
56+
'main_table.entity_id = grid_table.entity_id AND main_table.updated_at > grid_table.updated_at',
6557
[]
6658
);
6759

6860
$lastUpdatedAt = $this->lastUpdateTimeCache->get($gridTableName);
6961
if ($lastUpdatedAt) {
70-
$select->where($mainTableName . '.updated_at > ?', $lastUpdatedAt);
62+
$select->where('main_table.updated_at > ?', $lastUpdatedAt);
7163
}
7264

7365
return $this->connection->fetchAll($select, [], \Zend_Db::FETCH_COLUMN);

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/GridTest.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class GridTest extends TestCase
3636
*/
3737
private $connection;
3838

39+
/**
40+
* @var LastUpdateTimeCache|MockObject
41+
*/
42+
private $lastUpdateTimeCache;
43+
3944
/**
4045
* @var string
4146
*/
@@ -50,8 +55,9 @@ class GridTest extends TestCase
5055
* @var array
5156
*/
5257
private $columns = [
53-
'column_1_key' => 'column_1_value',
54-
'column_2_key' => 'column_2_value'
58+
'entity_id' => 'sales_order.entity_id',
59+
'status' => 'sales_order.status',
60+
'updated_at' => 'sales_order.updated_at',
5561
];
5662

5763
/**
@@ -62,7 +68,7 @@ protected function setUp(): void
6268
$objectManager = new ObjectManager($this);
6369
$this->notSyncedDataProvider = $this->createMock(NotSyncedDataProviderInterface::class);
6470
$this->connection = $this->createMock(ConnectionAdapterInterface::class);
65-
$lastUpdateTimeCache = $this->createMock(LastUpdateTimeCache::class);
71+
$this->lastUpdateTimeCache = $this->createMock(LastUpdateTimeCache::class);
6672

6773
$this->grid = $objectManager->getObject(
6874
Grid::class,
@@ -73,7 +79,7 @@ protected function setUp(): void
7379
'connection' => $this->connection,
7480
'_tables' => ['sales_order' => $this->mainTable, 'sales_order_grid' => $this->gridTable],
7581
'columns' => $this->columns,
76-
'lastUpdateTimeCache' => $lastUpdateTimeCache,
82+
'lastUpdateTimeCache' => $this->lastUpdateTimeCache,
7783
]
7884
);
7985
}
@@ -84,10 +90,16 @@ protected function setUp(): void
8490
public function testRefreshBySchedule()
8591
{
8692
$notSyncedIds = ['1', '2', '3'];
87-
$fetchResult = [
88-
['entity_id' => 1, 'updated_at' => date('Y-m-d H:i:s')],
89-
['entity_id' => 2, 'updated_at' => date('Y-m-d H:i:s')],
90-
];
93+
$fetchResult = [];
94+
for ($i = 1; $i <= 220; $i++) {
95+
$fetchResult[] = [
96+
'entity_id' => $i,
97+
'status' => 1,
98+
'updated_at' => '2021-01-01 01:02:03',
99+
];
100+
}
101+
$fetchResult[50]['updated_at'] = '2021-02-03 01:02:03';
102+
$fetchResult[150]['updated_at'] = '2021-03-04 01:02:03';
91103

92104
$this->notSyncedDataProvider->expects($this->atLeastOnce())
93105
->method('getIds')
@@ -117,6 +129,10 @@ public function testRefreshBySchedule()
117129
->with($this->gridTable, $fetchResult, array_keys($this->columns))
118130
->willReturn(array_count_values($notSyncedIds));
119131

132+
$this->lastUpdateTimeCache->expects($this->once())
133+
->method('save')
134+
->with($this->gridTable, '2021-03-04 01:02:03');
135+
120136
$this->grid->refreshBySchedule();
121137
}
122138
}

0 commit comments

Comments
 (0)