Skip to content

Commit 64263d8

Browse files
committed
B2B-2463: Improve custom attributes metadata fetching for category models in graphql
1 parent abe22bc commit 64263d8

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

app/code/Magento/Catalog/Model/Category/AttributeRepository.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class AttributeRepository implements CategoryAttributeRepositoryInterface
2929
*/
3030
private $eavConfig;
3131

32+
/**
33+
* @var array
34+
*/
35+
private $metadataCache;
36+
3237
/**
3338
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
3439
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
@@ -75,18 +80,21 @@ public function get($attributeCode)
7580
*/
7681
public function getCustomAttributesMetadata($dataObjectClassName = null)
7782
{
78-
$defaultAttributeSetId = $this->eavConfig
79-
->getEntityType(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE)
80-
->getDefaultAttributeSetId();
81-
$searchCriteria = $this->searchCriteriaBuilder->addFilters(
82-
[
83-
$this->filterBuilder
84-
->setField('attribute_set_id')
85-
->setValue($defaultAttributeSetId)
86-
->create(),
87-
]
88-
);
89-
90-
return $this->getList($searchCriteria->create())->getItems();
83+
if (empty($this->metadataCache[$dataObjectClassName])) {
84+
$defaultAttributeSetId = $this->eavConfig
85+
->getEntityType(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE)
86+
->getDefaultAttributeSetId();
87+
$searchCriteria = $this->searchCriteriaBuilder->addFilters(
88+
[
89+
$this->filterBuilder
90+
->setField('attribute_set_id')
91+
->setValue($defaultAttributeSetId)
92+
->create(),
93+
]
94+
);
95+
$this->metadataCache[$dataObjectClassName] = $this->getList($searchCriteria->create())
96+
->getItems();
97+
}
98+
return $this->metadataCache[$dataObjectClassName];
9199
}
92100
}

0 commit comments

Comments
 (0)