Skip to content

Commit a74feef

Browse files
committed
B2B-2452: Optimize Deferred Product Data Provider
1 parent 0ea99c7 commit a74feef

File tree

1 file changed

+12
-6
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Deferred

1 file changed

+12
-6
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Deferred/Product.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function addEavAttributes(array $attributeCodes) : void
100100
*/
101101
public function getProductBySku(string $sku, ContextInterface $context = null) : array
102102
{
103+
if (isset($this->productList[$sku])) {
104+
return $this->productList[$sku];
105+
}
106+
103107
$this->fetch($context);
104108

105109
if (!isset($this->productList[$sku])) {
@@ -113,13 +117,17 @@ public function getProductBySku(string $sku, ContextInterface $context = null) :
113117
* Fetch product data and return in array format. Keys for products will be their skus.
114118
*
115119
* @param null|ContextInterface $context
116-
* @return array
117120
*/
118-
private function fetch(ContextInterface $context = null) : array
121+
private function fetch(ContextInterface $context = null): void
119122
{
123+
if (empty($this->productSkus)) {
124+
return;
125+
}
126+
120127
$skusToFetch = array_diff($this->productSkus, array_keys($this->productList));
121-
if (empty($this->productSkus) || empty($skusToFetch)) {
122-
return $this->productList;
128+
129+
if (empty($skusToFetch)) {
130+
return;
123131
}
124132

125133
$this->searchCriteriaBuilder->addFilter(ProductInterface::SKU, $skusToFetch, 'in');
@@ -135,7 +143,5 @@ private function fetch(ContextInterface $context = null) : array
135143
foreach ($result->getItems() as $product) {
136144
$this->productList[$product->getSku()] = ['model' => $product];
137145
}
138-
139-
return $this->productList;
140146
}
141147
}

0 commit comments

Comments
 (0)