Skip to content

Commit f8dd4f0

Browse files
committed
MC-22212: 1213 Deadlock found when trying to get lock
1 parent 531663d commit f8dd4f0

File tree

3 files changed

+35
-94
lines changed

3 files changed

+35
-94
lines changed

app/code/Magento/CatalogInventory/Model/Plugin/PriceIndexUpdater.php

Lines changed: 0 additions & 79 deletions
This file was deleted.

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
*/
66
namespace Magento\CatalogInventory\Model\ResourceModel\Stock;
77

8-
use Magento\CatalogInventory\Api\Data\StockItemInterface;
8+
use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceIndexProcessor;
99
use Magento\CatalogInventory\Api\StockConfigurationInterface;
1010
use Magento\CatalogInventory\Model\Stock;
1111
use Magento\CatalogInventory\Model\Indexer\Stock\Processor;
1212
use Magento\Framework\Model\AbstractModel;
1313
use Magento\Framework\Model\ResourceModel\Db\Context;
1414
use Magento\Framework\DB\Select;
15-
use Magento\Framework\App\ObjectManager;
1615
use Magento\Framework\Stdlib\DateTime\DateTime;
1716

1817
/**
@@ -42,27 +41,33 @@ class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4241
*/
4342
private $dateTime;
4443

44+
/**
45+
* @var PriceIndexProcessor
46+
*/
47+
private $priceIndexProcessor;
48+
4549
/**
4650
* @param Context $context
4751
* @param Processor $processor
48-
* @param string $connectionName
4952
* @param StockConfigurationInterface $stockConfiguration
5053
* @param DateTime $dateTime
54+
* @param PriceIndexProcessor $priceIndexProcessor
55+
* @param string $connectionName
5156
*/
5257
public function __construct(
5358
Context $context,
5459
Processor $processor,
55-
$connectionName = null,
56-
StockConfigurationInterface $stockConfiguration = null,
57-
DateTime $dateTime = null
60+
StockConfigurationInterface $stockConfiguration,
61+
DateTime $dateTime,
62+
PriceIndexProcessor $priceIndexProcessor,
63+
$connectionName = null
5864
) {
5965
$this->stockIndexerProcessor = $processor;
6066
parent::__construct($context, $connectionName);
6167

62-
$this->stockConfiguration = $stockConfiguration ??
63-
ObjectManager::getInstance()->get(StockConfigurationInterface::class);
64-
$this->dateTime = $dateTime ??
65-
ObjectManager::getInstance()->get(DateTime::class);
68+
$this->stockConfiguration = $stockConfiguration;
69+
$this->dateTime = $dateTime;
70+
$this->priceIndexProcessor = $priceIndexProcessor;
6671
}
6772

6873
/**
@@ -144,10 +149,28 @@ protected function _prepareDataForTable(\Magento\Framework\DataObject $object, $
144149
protected function _afterSave(AbstractModel $object)
145150
{
146151
parent::_afterSave($object);
147-
/** @var StockItemInterface $object */
152+
153+
$productId = $object->getProductId();
148154
if ($this->processIndexEvents) {
149-
$this->stockIndexerProcessor->reindexRow($object->getProductId());
155+
$this->addCommitCallback(function () use ($productId) {
156+
$this->stockIndexerProcessor->reindexRow($productId);
157+
});
158+
150159
}
160+
$fields = [
161+
'is_in_stock',
162+
'use_config_manage_stock',
163+
'manage_stock',
164+
];
165+
foreach ($fields as $field) {
166+
if ($object->dataHasChangedFor($field)) {
167+
$this->addCommitCallback(function () use ($productId) {
168+
$this->priceIndexProcessor->reindexRow($productId);
169+
});
170+
break;
171+
}
172+
}
173+
151174
return $this;
152175
}
153176

app/code/Magento/CatalogInventory/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@
129129
</argument>
130130
</arguments>
131131
</type>
132-
<type name="Magento\CatalogInventory\Model\ResourceModel\Stock\Item">
133-
<plugin name="priceIndexUpdater" type="Magento\CatalogInventory\Model\Plugin\PriceIndexUpdater" />
134-
</type>
135132
<type name="Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save">
136133
<plugin name="massAction" type="Magento\CatalogInventory\Plugin\MassUpdateProductAttribute" />
137134
</type>

0 commit comments

Comments
 (0)