Skip to content

Commit 3477a71

Browse files
committed
MAGETWO-52836: Enable EAV attributes caching
1 parent 40345c5 commit 3477a71

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

app/code/Magento/Eav/Model/Entity/Attribute.php

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
3737
*/
3838
protected $_eventPrefix = 'eav_entity_attribute';
3939

40-
/**
41-
* @var AttributeCache
42-
*/
43-
private $attributeCache;
44-
4540
/**
4641
* Parameter name in event
4742
*
@@ -227,7 +222,7 @@ public function loadEntityAttributeIdBySet()
227222
public function beforeSave()
228223
{
229224
// prevent overriding product data
230-
if (isset($this->_data['attribute_code']) && $this->getReservedAttributeList()->isReservedAttribute($this)) {
225+
if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
231226
throw new LocalizedException(
232227
__(
233228
'The attribute code \'%1\' is reserved by system. Please try another attribute code',
@@ -304,32 +299,9 @@ public function beforeSave()
304299
public function afterSave()
305300
{
306301
$this->_getResource()->saveInSetIncluding($this);
307-
$this->getAttributeCache()->clear();
308302
return parent::afterSave();
309303
}
310304

311-
/**
312-
* @return $this
313-
*/
314-
public function afterDelete()
315-
{
316-
$this->getAttributeCache()->clear();
317-
return parent::afterDelete();
318-
}
319-
320-
/**
321-
* Attribute cache
322-
*
323-
* @return AttributeCache
324-
*/
325-
private function getAttributeCache()
326-
{
327-
if (!$this->attributeCache) {
328-
$this->attributeCache = ObjectManager::getInstance()->get(AttributeCache::class);
329-
}
330-
return $this->attributeCache;
331-
}
332-
333305
/**
334306
* Detect backend storage type using frontend input type
335307
*
@@ -512,22 +484,8 @@ public function __wakeup()
512484
parent::__wakeup();
513485
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
514486
$this->_localeDate = $objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
515-
$this->_localeResolver = $objectManager->get(\Magento\Catalog\Model\Product\ReservedAttributeList::class);
516-
$this->reservedAttributeList = $objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
487+
$this->_localeResolver = $objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
488+
$this->reservedAttributeList = $objectManager->get(\Magento\Catalog\Model\Product\ReservedAttributeList::class);
517489
$this->dateTimeFormatter = $objectManager->get(DateTimeFormatterInterface::class);
518490
}
519-
520-
/**
521-
* @return \Magento\Catalog\Model\Product\ReservedAttributeList|mixed
522-
*/
523-
private function getReservedAttributeList()
524-
{
525-
if ($this->reservedAttributeList) {
526-
$this->reservedAttributeList = \Magento\Framework\App\ObjectManager::getInstance()->get(
527-
\Magento\Catalog\Model\Product\ReservedAttributeList::class
528-
);
529-
}
530-
531-
return $this->reservedAttributeList;
532-
}
533491
}

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ protected function _afterSave(AbstractModel $object)
215215
return parent::_afterSave($object);
216216
}
217217

218+
/**
219+
* Perform actions after object delete
220+
*
221+
* @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
222+
* @return $this
223+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
224+
*/
225+
protected function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
226+
{
227+
$this->getConfig()->clear();
228+
$this->getAttributeCache()->clear();
229+
return $this;
230+
}
218231
/**
219232
* @return AttributeCache
220233
* @deprecated

0 commit comments

Comments
 (0)