Skip to content

Commit 3b95250

Browse files
committed
MDEE-974: Product Feed index taking long time to execute
1 parent e914a97 commit 3b95250

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

CatalogDataExporter/Model/Provider/Products.php

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ public function execute(
137137
if ($storeViewItemN[$storeViewCode] % $metadata->getBatchSize() == 0
138138
|| count($mappedProducts) % $metadata->getBatchSize() == 0) {
139139
$this->processProducts(
140-
['storeViewCode' => $mappedProducts[$storeViewCode]],
141-
['storeViewCode' => $attributesData[$storeViewCode]],
140+
$mappedProducts,
141+
$attributesData,
142142
$dataProcessorCallback,
143-
$metadata
143+
$storeViewCode
144144
);
145145
unset($mappedProducts[$storeViewCode], $attributesData[$storeViewCode]);
146146
}
@@ -158,7 +158,7 @@ public function execute(
158158
)
159159
);
160160
} else {
161-
$this->processProducts($mappedProducts, $attributesData, $dataProcessorCallback, $metadata);
161+
$this->processProducts($mappedProducts, $attributesData, $dataProcessorCallback);
162162
}
163163
}
164164

@@ -179,25 +179,28 @@ public function get(array $values) : array
179179
* @param array $mappedProducts
180180
* @param array $attributesData
181181
* @param callable $dataProcessorCallback
182-
* @param FeedIndexMetadata $metadata
182+
* @param string|null $storeViewCode
183183
* @return void
184184
* @throws UnableRetrieveData
185185
*/
186186
private function processProducts(
187187
array $mappedProducts,
188188
array $attributesData,
189189
callable $dataProcessorCallback,
190-
FeedIndexMetadata $metadata
190+
string $storeViewCode = null
191191
): void {
192192
$output = [];
193-
194-
foreach ($mappedProducts as $storeCode => $products) {
195-
$output[] = \array_map(function ($row) {
196-
return $this->formatter->format($row);
197-
}, \array_replace_recursive(
198-
$products,
199-
$this->entityEavAttributesResolver->resolve($attributesData[$storeCode], $storeCode)
200-
));
193+
if (null === $storeViewCode) {
194+
foreach ($mappedProducts as $mappedStoreViewCode => $products) {
195+
$this->formatOutput($products, $attributesData[$storeViewCode], $output, $mappedStoreViewCode);
196+
}
197+
} else {
198+
$this->formatOutput(
199+
$mappedProducts[$storeViewCode],
200+
$attributesData[$storeViewCode],
201+
$output,
202+
$storeViewCode
203+
);
201204
}
202205

203206
$errorEntityIds = [];
@@ -218,4 +221,28 @@ private function processProducts(
218221

219222
$dataProcessorCallback($this->get(\array_merge(...$output)));
220223
}
224+
225+
/**
226+
* Format output
227+
*
228+
* @param array $products
229+
* @param array $attributesData
230+
* @param array $output
231+
* @param string $storeViewCode
232+
* @return void
233+
* @throws UnableRetrieveData
234+
*/
235+
private function formatOutput(
236+
array $products,
237+
array $attributesData,
238+
array &$output,
239+
string $storeViewCode
240+
): void {
241+
$output[] = \array_map(function ($row) {
242+
return $this->formatter->format($row);
243+
}, \array_replace_recursive(
244+
$products,
245+
$this->entityEavAttributesResolver->resolve($attributesData, $storeViewCode)
246+
));
247+
}
221248
}

0 commit comments

Comments
 (0)