Skip to content

Commit eeaa059

Browse files
committed
ACP2E-2504: [TMNA] Slow Query Investigation
1 parent b9f57bd commit eeaa059

File tree

12 files changed

+273
-297
lines changed

12 files changed

+273
-297
lines changed

app/code/Magento/Catalog/Cron/SynchronizeWebsiteAttributes.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
1010

1111
/**
12-
* Class SynchronizeWebsiteAttributes
13-
* @package Magento\Catalog\Cron
12+
* @deprecated
13+
* @see \Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific\ValueSynchronizer
1414
*/
1515
class SynchronizeWebsiteAttributes
1616
{
@@ -20,7 +20,6 @@ class SynchronizeWebsiteAttributes
2020
private $synchronizer;
2121

2222
/**
23-
* SynchronizeWebsiteAttributes constructor.
2423
* @param WebsiteAttributesSynchronizer $synchronizer
2524
*/
2625
public function __construct(WebsiteAttributesSynchronizer $synchronizer)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* ADOBE CONFIDENTIAL
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific;
20+
21+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
22+
use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
23+
use Magento\Framework\Bulk\BulkManagementInterface;
24+
use Magento\Framework\DataObject\IdentityGeneratorInterface;
25+
use Magento\Framework\Exception\LocalizedException;
26+
use Magento\Framework\Serialize\SerializerInterface;
27+
28+
class Scheduler
29+
{
30+
private const TOPIC_NAME = 'catalog_website_attribute_value_sync';
31+
32+
/**
33+
* @param BulkManagementInterface $bulkManagement
34+
* @param IdentityGeneratorInterface $identityGenerator
35+
* @param OperationInterfaceFactory $operationFactory
36+
* @param SerializerInterface $serializer
37+
*/
38+
public function __construct(
39+
private BulkManagementInterface $bulkManagement,
40+
private IdentityGeneratorInterface $identityGenerator,
41+
private OperationInterfaceFactory $operationFactory,
42+
private SerializerInterface $serializer
43+
) {
44+
}
45+
46+
/**
47+
* Schedule website specific values synchronization.
48+
*
49+
* @param int $storeId
50+
* @return void
51+
* @throws LocalizedException
52+
*/
53+
public function execute(int $storeId): void
54+
{
55+
$bulkUuid = $this->identityGenerator->generateId();
56+
$operation = $this->operationFactory->create(
57+
[
58+
'data' => [
59+
'bulk_uuid' => $bulkUuid,
60+
'topic_name' => self::TOPIC_NAME,
61+
'serialized_data' => $this->serializer->serialize(['store_id' => $storeId]),
62+
'status' => OperationInterface::STATUS_TYPE_OPEN,
63+
]
64+
]
65+
);
66+
$bulkDescription = __('Synchronize website specific attributes values');
67+
$result = $this->bulkManagement->scheduleBulk($bulkUuid, [$operation], $bulkDescription);
68+
if (!$result) {
69+
throw new LocalizedException(__('Something went wrong while scheduling operations.'));
70+
}
71+
}
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* ADOBE CONFIDENTIAL
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific;
20+
21+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
22+
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
23+
use Magento\Framework\EntityManager\EntityManager;
24+
use Magento\Framework\Exception\LocalizedException;
25+
use Magento\Framework\Serialize\SerializerInterface;
26+
use Psr\Log\LoggerInterface;
27+
28+
class ValueSynchronizer
29+
{
30+
/**
31+
* @param EntityManager $entityManager
32+
* @param SerializerInterface $serializer
33+
* @param LoggerInterface $logger
34+
* @param WebsiteAttributesSynchronizer $websiteAttributesSynchronizer
35+
*/
36+
public function __construct(
37+
private EntityManager $entityManager,
38+
private SerializerInterface $serializer,
39+
private LoggerInterface $logger,
40+
private WebsiteAttributesSynchronizer $websiteAttributesSynchronizer
41+
) {
42+
}
43+
44+
/**
45+
* Process website specific values synchronization.
46+
*
47+
* @param OperationInterface $operation
48+
* @return void
49+
*/
50+
public function process(OperationInterface $operation): void
51+
{
52+
try {
53+
$serializedData = $operation->getSerializedData();
54+
$data = $this->serializer->unserialize($serializedData);
55+
$this->websiteAttributesSynchronizer->synchronizeStoreValues($data['store_id']);
56+
$operation->setStatus(OperationInterface::STATUS_TYPE_COMPLETE);
57+
$operation->setResultMessage(null);
58+
} catch (LocalizedException $e) {
59+
$operation->setStatus(OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED);
60+
$operation->setErrorCode($e->getCode());
61+
$operation->setResultMessage($e->getMessage());
62+
} catch (\Throwable $e) {
63+
$this->logger->critical($e);
64+
$operation->setStatus(OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED);
65+
$operation->setErrorCode($e->getCode());
66+
$operation->setResultMessage(
67+
__('Sorry, something went wrong during update synchronization. Please see log for details.')
68+
);
69+
}
70+
$this->entityManager->save($operation);
71+
}
72+
}

0 commit comments

Comments
 (0)