Skip to content

Commit 96e5bb9

Browse files
committed
ACP2E-2504: [TMNA] Slow Query Investigation
1 parent a520f85 commit 96e5bb9

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

app/code/Magento/Catalog/Model/Attribute/Backend/WebsiteSpecific/ValueSynchronizer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
2222
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
23+
use Magento\Framework\DB\Adapter\ConnectionException;
24+
use Magento\Framework\DB\Adapter\DeadlockException;
25+
use Magento\Framework\DB\Adapter\LockWaitException;
2326
use Magento\Framework\EntityManager\EntityManager;
2427
use Magento\Framework\Exception\LocalizedException;
2528
use Magento\Framework\Serialize\SerializerInterface;
@@ -55,6 +58,10 @@ public function process(OperationInterface $operation): void
5558
$this->websiteAttributesSynchronizer->synchronizeStoreValues($data['store_id']);
5659
$operation->setStatus(OperationInterface::STATUS_TYPE_COMPLETE);
5760
$operation->setResultMessage(null);
61+
} catch (LockWaitException|DeadlockException|ConnectionException $e) {
62+
$operation->setStatus(OperationInterface::STATUS_TYPE_RETRIABLY_FAILED);
63+
$operation->setErrorCode($e->getCode());
64+
$operation->setResultMessage($e->getMessage());
5865
} catch (LocalizedException $e) {
5966
$operation->setStatus(OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED);
6067
$operation->setErrorCode($e->getCode());

app/code/Magento/Catalog/Model/ResourceModel/Attribute/WebsiteAttributesSynchronizer.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,8 @@ public function synchronize()
141141
*/
142142
public function synchronizeStoreValues(int $storeId): void
143143
{
144-
$this->connection->beginTransaction();
145-
try {
146-
foreach (array_keys($this->tableMetaDataClass) as $tableName) {
147-
$this->synchronizeTable($tableName, $storeId);
148-
}
149-
$this->connection->commit();
150-
} catch (\Exception $e) {
151-
$this->connection->rollBack();
152-
throw $e;
144+
foreach (array_keys($this->tableMetaDataClass) as $tableName) {
145+
$this->synchronizeTable($tableName, $storeId);
153146
}
154147
}
155148

app/code/Magento/Catalog/Test/Unit/Observer/SynchronizeWebsiteAttributesOnStoreChangeTest.php

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\Catalog\Test\Unit\Observer;
99

10-
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
10+
use Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific\Scheduler;
1111
use Magento\Catalog\Observer\SynchronizeWebsiteAttributesOnStoreChange;
1212
use Magento\Framework\Event\Observer;
1313
use Magento\Store\Model\Store;
@@ -25,17 +25,11 @@ public function testExecuteInvalidStore($invalidDataObject)
2525
'data_object' => $invalidDataObject,
2626
]);
2727

28-
$synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class)
29-
->disableOriginalConstructor()
30-
->setMethods([
31-
'scheduleSynchronization',
32-
])
33-
->getMock();
34-
35-
$synchronizerMock->expects($this->never())
36-
->method('scheduleSynchronization');
28+
$schedulerMock = $this->createMock(Scheduler::class);
29+
$schedulerMock->expects(self::never())
30+
->method('execute');
3731

38-
$instance = new SynchronizeWebsiteAttributesOnStoreChange($synchronizerMock);
32+
$instance = new SynchronizeWebsiteAttributesOnStoreChange($schedulerMock);
3933
$result = $instance->execute($eventObserver);
4034
$this->assertNull($result);
4135
}
@@ -62,17 +56,11 @@ public function testExecuteStoreHasNoChanges(Store $store)
6256
'data_object' => $store,
6357
]);
6458

65-
$synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class)
66-
->disableOriginalConstructor()
67-
->setMethods([
68-
'scheduleSynchronization',
69-
])
70-
->getMock();
71-
72-
$synchronizerMock->expects($this->never())
73-
->method('scheduleSynchronization');
59+
$schedulerMock = $this->createMock(Scheduler::class);
60+
$schedulerMock->expects(self::never())
61+
->method('execute');
7462

75-
$instance = new SynchronizeWebsiteAttributesOnStoreChange($synchronizerMock);
63+
$instance = new SynchronizeWebsiteAttributesOnStoreChange($schedulerMock);
7664
$result = $instance->execute($eventObserver);
7765
$this->assertNull($result);
7866
}
@@ -116,17 +104,11 @@ public function testExecuteWebsiteIdIsNoChangedAndNotNew(Store $store)
116104
'data_object' => $store,
117105
]);
118106

119-
$synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class)
120-
->disableOriginalConstructor()
121-
->setMethods([
122-
'scheduleSynchronization',
123-
])
124-
->getMock();
125-
126-
$synchronizerMock->expects($this->never())
127-
->method('scheduleSynchronization');
107+
$schedulerMock = $this->createMock(Scheduler::class);
108+
$schedulerMock->expects(self::never())
109+
->method('execute');
128110

129-
$instance = new SynchronizeWebsiteAttributesOnStoreChange($synchronizerMock);
111+
$instance = new SynchronizeWebsiteAttributesOnStoreChange($schedulerMock);
130112
$result = $instance->execute($eventObserver);
131113
$this->assertNull($result);
132114
}
@@ -189,17 +171,11 @@ public function testExecuteSuccess(Store $store)
189171
'data_object' => $store,
190172
]);
191173

192-
$synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class)
193-
->disableOriginalConstructor()
194-
->setMethods([
195-
'scheduleSynchronization',
196-
])
197-
->getMock();
198-
199-
$synchronizerMock->expects($this->once())
200-
->method('scheduleSynchronization');
174+
$schedulerMock = $this->createMock(Scheduler::class);
175+
$schedulerMock->expects(self::once())
176+
->method('execute');
201177

202-
$instance = new SynchronizeWebsiteAttributesOnStoreChange($synchronizerMock);
178+
$instance = new SynchronizeWebsiteAttributesOnStoreChange($schedulerMock);
203179
$result = $instance->execute($eventObserver);
204180
$this->assertNull($result);
205181
}

0 commit comments

Comments
 (0)