Skip to content

Commit 614356e

Browse files
committed
ACPT-1572: Slow saving of stores/websites
1 parent 07187f2 commit 614356e

File tree

2 files changed

+83
-28
lines changed

2 files changed

+83
-28
lines changed

app/code/Magento/Store/Model/Group.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99
*/
1010
namespace Magento\Store\Model;
1111

12+
use Magento\Config\Model\ResourceModel\Config\Data;
13+
use Magento\Framework\Api\AttributeValueFactory;
14+
use Magento\Framework\Api\ExtensionAttributesFactory;
15+
use Magento\Framework\App\Cache\TypeListInterface;
1216
use Magento\Framework\App\ObjectManager;
17+
use Magento\Framework\Data\Collection\AbstractDb;
18+
use Magento\Framework\Event\ManagerInterface;
1319
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
20+
use Magento\Framework\Model\Context;
21+
use Magento\Framework\Model\ResourceModel\AbstractResource;
22+
use Magento\Framework\Registry;
23+
use Magento\PageCache\Model\Cache\Type;
24+
use Magento\Store\Model\ResourceModel\Store\CollectionFactory;
1425
use Magento\Store\Model\Validation\StoreValidator;
1526

1627
/**
@@ -115,19 +126,25 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
115126
private $modelValidator;
116127

117128
/**
118-
* @param \Magento\Framework\Model\Context $context
119-
* @param \Magento\Framework\Registry $registry
120-
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
121-
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
122-
* @param \Magento\Config\Model\ResourceModel\Config\Data $configDataResource
123-
* @param ResourceModel\Store\CollectionFactory $storeListFactory
129+
* @var TypeListInterface
130+
*/
131+
private TypeListInterface $typeList;
132+
133+
/**
134+
* @param Context $context
135+
* @param Registry $registry
136+
* @param ExtensionAttributesFactory $extensionFactory
137+
* @param AttributeValueFactory $customAttributeFactory
138+
* @param Data $configDataResource
139+
* @param CollectionFactory $storeListFactory
124140
* @param StoreManagerInterface $storeManager
125-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
126-
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
141+
* @param AbstractResource|null $resource
142+
* @param AbstractDb|null $resourceCollection
127143
* @param array $data
128-
* @param \Magento\Framework\Event\ManagerInterface|null $eventManager
144+
* @param ManagerInterface|null $eventManager
129145
* @param PoisonPillPutInterface|null $pillPut
130146
* @param StoreValidator|null $modelValidator
147+
* @param TypeListInterface|null $typeList
131148
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
132149
*/
133150
public function __construct(
@@ -143,7 +160,8 @@ public function __construct(
143160
array $data = [],
144161
\Magento\Framework\Event\ManagerInterface $eventManager = null,
145162
PoisonPillPutInterface $pillPut = null,
146-
StoreValidator $modelValidator = null
163+
StoreValidator $modelValidator = null,
164+
TypeListInterface $typeList = null
147165
) {
148166
$this->_configDataResource = $configDataResource;
149167
$this->_storeListFactory = $storeListFactory;
@@ -163,6 +181,7 @@ public function __construct(
163181
$resourceCollection,
164182
$data
165183
);
184+
$this->typeList = $typeList ?: ObjectManager::getInstance()->get(TypeListInterface::class);
166185
}
167186

168187
/**
@@ -457,6 +476,7 @@ public function afterDelete()
457476
$this->_storeManager->reinitStores();
458477
$this->eventManager->dispatch($this->_eventPrefix . '_delete', ['group' => $group]);
459478
});
479+
$this->typeList->cleanType(Type::TYPE_IDENTIFIER);
460480
$result = parent::afterDelete();
461481

462482
if ($this->getId() === $this->getWebsite()->getDefaultGroupId()) {
@@ -484,6 +504,9 @@ public function afterSave()
484504
$this->_storeManager->reinitStores();
485505
$this->eventManager->dispatch($this->_eventPrefix . '_save', ['group' => $group]);
486506
});
507+
if (!$this->isObjectNew()) {
508+
$this->typeList->invalidate([Type::TYPE_IDENTIFIER]);
509+
}
487510
$this->pillPut->put();
488511
return parent::afterSave();
489512
}

app/code/Magento/Store/Model/Website.php

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
*/
66
namespace Magento\Store\Model;
77

8+
use Magento\Config\Model\ResourceModel\Config\Data;
9+
use Magento\Directory\Model\CurrencyFactory;
10+
use Magento\Framework\Api\AttributeValueFactory;
11+
use Magento\Framework\Api\ExtensionAttributesFactory;
12+
use Magento\Framework\App\Cache\Type\Config;
13+
use Magento\Framework\App\Cache\TypeListInterface;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\Data\Collection\AbstractDb;
17+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
18+
use Magento\Framework\Model\Context;
19+
use Magento\Framework\Model\ResourceModel\AbstractResource;
20+
use Magento\Framework\Registry;
21+
use Magento\PageCache\Model\Cache\Type;
22+
use Magento\Store\Model\ResourceModel\Store\CollectionFactory;
23+
824
/**
925
* Core Website model
1026
*
@@ -160,7 +176,7 @@ class Website extends \Magento\Framework\Model\AbstractExtensibleModel implement
160176
protected $_currencyFactory;
161177

162178
/**
163-
* @var \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface
179+
* @var PoisonPillPutInterface
164180
*/
165181
private $pillPut;
166182

@@ -170,21 +186,27 @@ class Website extends \Magento\Framework\Model\AbstractExtensibleModel implement
170186
private $_coreConfig;
171187

172188
/**
173-
* @param \Magento\Framework\Model\Context $context
174-
* @param \Magento\Framework\Registry $registry
175-
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
176-
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
177-
* @param \Magento\Config\Model\ResourceModel\Config\Data $configDataResource
178-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
179-
* @param \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeListFactory
180-
* @param \Magento\Store\Model\GroupFactory $storeGroupFactory
181-
* @param \Magento\Store\Model\WebsiteFactory $websiteFactory
182-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
183-
* @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
184-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
185-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
189+
* @var TypeListInterface
190+
*/
191+
private TypeListInterface $typeList;
192+
193+
/**
194+
* @param Context $context
195+
* @param Registry $registry
196+
* @param ExtensionAttributesFactory $extensionFactory
197+
* @param AttributeValueFactory $customAttributeFactory
198+
* @param Data $configDataResource
199+
* @param ScopeConfigInterface $coreConfig
200+
* @param CollectionFactory $storeListFactory
201+
* @param GroupFactory $storeGroupFactory
202+
* @param WebsiteFactory $websiteFactory
203+
* @param StoreManagerInterface $storeManager
204+
* @param CurrencyFactory $currencyFactory
205+
* @param AbstractResource|null $resource
206+
* @param AbstractDb|null $resourceCollection
186207
* @param array $data
187-
* @param \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface|null $pillPut
208+
* @param PoisonPillPutInterface|null $pillPut
209+
* @param TypeListInterface|null $typeList
188210
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
189211
*/
190212
public function __construct(
@@ -202,7 +224,8 @@ public function __construct(
202224
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
203225
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
204226
array $data = [],
205-
\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null
227+
PoisonPillPutInterface $pillPut = null,
228+
TypeListInterface $typeList = null
206229
) {
207230
parent::__construct(
208231
$context,
@@ -220,8 +243,8 @@ public function __construct(
220243
$this->_websiteFactory = $websiteFactory;
221244
$this->_storeManager = $storeManager;
222245
$this->_currencyFactory = $currencyFactory;
223-
$this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance()
224-
->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class);
246+
$this->pillPut = $pillPut ?: ObjectManager::getInstance()->get(PoisonPillPutInterface::class);
247+
$this->typeList = $typeList ?: ObjectManager::getInstance()->get(TypeListInterface::class);
225248
}
226249

227250
/**
@@ -584,6 +607,13 @@ public function beforeDelete()
584607
public function afterDelete()
585608
{
586609
$this->_storeManager->reinitStores();
610+
$types = [
611+
Type::TYPE_IDENTIFIER,
612+
Config::TYPE_IDENTIFIER
613+
];
614+
foreach ($types as $type) {
615+
$this->typeList->cleanType($type);
616+
}
587617
parent::afterDelete();
588618
return $this;
589619
}
@@ -598,6 +628,8 @@ public function afterSave()
598628
{
599629
if ($this->isObjectNew()) {
600630
$this->_storeManager->reinitStores();
631+
} else {
632+
$this->typeList->invalidate([Type::TYPE_IDENTIFIER, Config::TYPE_IDENTIFIER]);
601633
}
602634
$this->pillPut->put();
603635
return parent::afterSave();

0 commit comments

Comments
 (0)