Skip to content

Commit 9345a6b

Browse files
committed
ACP2E-1697 Improve speed of catalogrule reindex process
1 parent 647b34e commit 9345a6b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,16 @@ public function callbackValidateProduct($args)
405405
$product->setData($args['row']);
406406

407407
$websites = $this->_getWebsitesMap();
408+
$websiteIds = $this->getWebsiteIds();
409+
if (!is_array($websiteIds)) {
410+
$websiteIds = explode(',', $websiteIds);
411+
}
408412
$results = [];
409413

410414
foreach ($websites as $websiteId => $defaultStoreId) {
415+
if (!in_array($websiteId, $websiteIds)) {
416+
continue;
417+
}
411418
$product->setStoreId($defaultStoreId);
412419
$results[$websiteId] = $this->getConditions()->validate($product);
413420
}

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ public function testCallbackValidateProduct($validate): void
207207
'updated_at' => '2014-06-25 14:37:15'
208208
];
209209
$this->storeManager->expects($this->any())->method('getWebsites')->with(false)
210-
->willReturn([$this->websiteModel, $this->websiteModel]);
210+
->willReturn([$this->websiteModel, $this->websiteModel, $this->websiteModel]);
211211
$this->websiteModel
212212
->method('getId')
213-
->willReturnOnConsecutiveCalls('1', '2');
213+
->willReturnOnConsecutiveCalls('1', '2', '3');
214214
$this->websiteModel->expects($this->any())->method('getDefaultStore')
215215
->willReturn($this->storeModel);
216216
$this->storeModel
217217
->method('getId')
218-
->willReturnOnConsecutiveCalls('1', '2');
218+
->willReturnOnConsecutiveCalls('1', '2', '3');
219219
$this->combineFactory->expects($this->any())->method('create')
220220
->willReturn($this->condition);
221221
$this->condition->expects($this->any())->method('validate')
@@ -224,12 +224,14 @@ public function testCallbackValidateProduct($validate): void
224224
$this->productModel->expects($this->any())->method('getId')
225225
->willReturn(1);
226226

227+
$this->rule->setWebsiteIds('1,2');
227228
$this->rule->callbackValidateProduct($args);
228229

229230
$matchingProducts = $this->rule->getMatchingProductIds();
230231
foreach ($matchingProducts['1'] as $matchingRules) {
231232
$this->assertEquals($validate, $matchingRules);
232233
}
234+
$this->assertNull($matchingProducts['1']['3'] ?? null);
233235
}
234236

235237
/**

lib/internal/Magento/Framework/Model/ResourceModel/Iterator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public function walk($query, array $callbacks, array $args = [], $connection = n
3333
foreach ($callbacks as $callback) {
3434
$result = call_user_func($callback, $args);
3535
if (!empty($result)) {
36-
$args = array_merge($args, (array)$result);
36+
foreach ((array)$result as $key => $value) {
37+
$args[$key] = $value;
38+
}
3739
}
3840
}
3941
$args['idx']++;

0 commit comments

Comments
 (0)