Skip to content

Commit d63a584

Browse files
committed
MAGETWO-62691: [Performance] EAV attributes caching optimization
1 parent e64cc13 commit d63a584

File tree

6 files changed

+6
-44
lines changed

6 files changed

+6
-44
lines changed

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ public function testGetList()
715715
'',
716716
false
717717
);
718-
$extendedSearchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false);
719718
$productAttributeSearchResultsMock = $this->getMockBuilder(ProductAttributeInterface::class)
720719
->disableOriginalConstructor()
721720
->setMethods(['getItems'])
@@ -729,14 +728,8 @@ public function testGetList()
729728
);
730729

731730
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
732-
$this->searchCriteriaBuilderMock->expects($this->once())->method('create')
733-
->willReturn($extendedSearchCriteriaMock);
734-
$this->metadataServiceMock->expects($this->once())->method('getList')->with($extendedSearchCriteriaMock)
735-
->willReturn($productAttributeSearchResultsMock);
736-
$productAttributeSearchResultsMock->expects($this->once())->method('getItems')
737-
->willReturn([$productAttributeMock]);
738-
$productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
739-
$collectionMock->expects($this->once())->method('addAttributeToSelect')->with($attributeCode);
731+
732+
$collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*');
740733
$collectionMock->expects($this->exactly(2))->method('joinAttribute')->withConsecutive(
741734
['status', 'catalog_product/status', 'entity_id', null, 'inner'],
742735
['visibility', 'catalog_product/visibility', 'entity_id', null, 'inner']

app/code/Magento/Customer/Test/Unit/Model/Attribute/Data/PostcodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function setUp()
6464
public function testValidateValue($value, $expected, $countryId, $isOptional)
6565
{
6666
$storeLabel = 'Zip/Postal Code';
67-
$this->attributeMock->expects($this->once())
67+
$this->attributeMock->expects($this->any())
6868
->method('getStoreLabel')
6969
->willReturn($storeLabel);
7070

app/code/Magento/Eav/Model/Attribute/Data/Date.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public function validateValue($value)
4040
$errors = [];
4141
$attribute = $this->getAttribute();
4242

43-
4443
if ($value === false) {
4544
// try to load original value and validate it
4645
$value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());

app/code/Magento/Eav/Model/Attribute/Data/Text.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function validateValue($value)
6262
$errors = [];
6363
$attribute = $this->getAttribute();
6464

65-
6665
if ($value === false) {
6766
// try to load original value and validate it
6867
$value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());

app/code/Magento/Eav/Model/Config.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ protected function _initAttributes($entityType)
471471
* Get attributes by entity type
472472
*
473473
* @deprecated
474-
* @see \Magento\Eav\Model\Config::getEntityAttributes
474+
* @see \Magento\Eav\Model\Config::getEntityAttributes
475475
*
476476
* @param string $entityType
477477
* @return AbstractAttribute[]
@@ -540,7 +540,7 @@ private function createAttribute($model)
540540
* Get codes of all entity type attributes
541541
*
542542
* @deprecated
543-
* @see \Magento\Eav\Model\Config::getEntityAttributes
543+
* @see \Magento\Eav\Model\Config::getEntityAttributes
544544
*
545545
* @param mixed $entityType
546546
* @param \Magento\Framework\DataObject $object
@@ -572,7 +572,6 @@ public function getEntityAttributes($entityType, $object = null)
572572
}
573573
$cacheKey = self::ATTRIBUTES_CACHE_ID . '-' . $entityType->getId() . '-' . $storeId . '-' . $attributeSetId;
574574

575-
576575
if (isset($this->attributesPerSet[$cacheKey])) {
577576
return $this->attributesPerSet[$cacheKey];
578577
}
@@ -581,7 +580,6 @@ public function getEntityAttributes($entityType, $object = null)
581580
? $this->serializer->unserialize($attributes)
582581
: null;
583582

584-
585583
$attributes = [];
586584
if ($attributesData === null) {
587585
if ($attributeSetId) {

app/code/Magento/Eav/Test/Unit/Model/ConfigTest.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ public function testGetAttributeCache($cacheEnabled, $loadCalls, $unserializeCal
120120
->willReturnSelf();
121121
$entityAttributeMock->expects($this->atLeastOnce())->method('loadByCode')
122122
->willReturnSelf();
123-
$entityAttributeMock->expects($this->atLeastOnce())->method('toArray')
124-
->willReturn($attributeData);
123+
125124
$factoryCalls = [
126125
[
127126
Collection::class,
@@ -135,22 +134,6 @@ public function testGetAttributeCache($cacheEnabled, $loadCalls, $unserializeCal
135134
],
136135
];
137136

138-
$this->cacheStateMock
139-
->expects($this->atLeastOnce())
140-
->method('isEnabled')
141-
->with(Cache::TYPE_IDENTIFIER)
142-
->willReturn($cacheEnabled);
143-
$this->cacheMock
144-
->expects($this->exactly($loadCalls))
145-
->method('load')
146-
->with(Config::ATTRIBUTES_CACHE_ID . 'entity_type_code')
147-
->willReturn($cachedValue);
148-
$this->serializerMock
149-
->expects($this->exactly($unserializeCalls))
150-
->method('unserialize')
151-
->with($cachedValue)
152-
->willReturn([$attributeData]);
153-
154137
$entityTypeData = [
155138
'entity_type_id' => 'entity_type_id',
156139
'entity_type_code' => 'entity_type_code'
@@ -265,16 +248,6 @@ public function testGetAttributes($cacheEnabled, $loadCalls, $unserializeCalls,
265248
->method('isEnabled')
266249
->with(Cache::TYPE_IDENTIFIER)
267250
->willReturn($cacheEnabled);
268-
$this->cacheMock
269-
->expects($this->exactly($loadCalls))
270-
->method('load')
271-
->with(Config::ATTRIBUTES_CACHE_ID . 'entity_type_code')
272-
->willReturn($cachedValue);
273-
$this->serializerMock
274-
->expects($this->exactly($unserializeCalls))
275-
->method('unserialize')
276-
->with($cachedValue)
277-
->willReturn([$attributeData]);
278251

279252
$entityTypeData = [
280253
'entity_type_id' => 'entity_type_id',

0 commit comments

Comments
 (0)