Skip to content

Commit daef4b4

Browse files
committed
MAGETWO-90572: Optimize retrieving product attributes
1 parent b77e9a6 commit daef4b4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
1313
use Magento\Framework\Api\AttributeValueFactory;
1414
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\App\ObjectManager;
1516
use Magento\Framework\DataObject\IdentityInterface;
1617
use Magento\Framework\Pricing\SaleableInterface;
1718

@@ -346,6 +347,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
346347
*/
347348
protected $linkTypeProvider;
348349

350+
/**
351+
* @var \Magento\Eav\Model\Config|null
352+
*/
353+
private $eavConfig;
354+
349355
/**
350356
* Product constructor.
351357
* @param \Magento\Framework\Model\Context $context
@@ -384,6 +390,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
384390
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
385391
* @param array $data
386392
*
393+
* @param \Magento\Eav\Model\Config|null $config
387394
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
388395
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
389396
*/
@@ -422,7 +429,8 @@ public function __construct(
422429
EntryConverterPool $mediaGalleryEntryConverterPool,
423430
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
424431
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
425-
array $data = []
432+
array $data = [],
433+
\Magento\Eav\Model\Config $config = null
426434
) {
427435
$this->metadataService = $metadataService;
428436
$this->_itemOptionFactory = $itemOptionFactory;
@@ -461,6 +469,7 @@ public function __construct(
461469
$resourceCollection,
462470
$data
463471
);
472+
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
464473
}
465474

466475
/**
@@ -479,7 +488,10 @@ protected function _construct()
479488
protected function getCustomAttributesCodes()
480489
{
481490
if ($this->customAttributesCodes === null) {
482-
$this->customAttributesCodes = $this->getEavAttributesCodes($this->metadataService);
491+
$this->customAttributesCodes = array_keys($this->eavConfig->getEntityAttributes(
492+
self::ENTITY,
493+
$this
494+
));
483495
$this->customAttributesCodes = array_diff($this->customAttributesCodes, $this->interfaceAttributes);
484496
}
485497
return $this->customAttributesCodes;

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,9 @@ public function getList($entityTypeCode, \Magento\Framework\Api\SearchCriteriaIn
132132
$attributeCollection->addAttributeGrouping();
133133

134134
$attributes = [];
135-
// If search criteria not specified try to load all attributes for speedup
136-
if (!$searchCriteria->getFilterGroups()) {
137-
$attributes = $this->eavConfig->getEntityAttributes($entityTypeCode);
138-
} else {
139-
/** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */
140-
foreach ($attributeCollection as $attribute) {
141-
$attributes[] = $this->get($entityTypeCode, $attribute->getAttributeCode());
142-
}
135+
/** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */
136+
foreach ($attributeCollection as $attribute) {
137+
$attributes[] = $this->get($entityTypeCode, $attribute->getAttributeCode());
143138
}
144139

145140
/** @var \Magento\Eav\Api\Data\AttributeSearchResultsInterface $searchResults */

0 commit comments

Comments
 (0)