Skip to content

Commit 957d4d2

Browse files
author
Volodymyr Kublytskyi
committed
Merge magento-partners/magento2ce#38.
2 parents 2b7f641 + cb79e52 commit 957d4d2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/internal/Magento/Framework/Mview/Test/Unit/ViewTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ public function testUpdate()
263263
$currentVersionId = 3;
264264
$lastVersionId = 1;
265265
$listId = [2, 3];
266-
$defaultBatchSize = 1000;
267266

268267
$this->stateMock->expects($this->any())
269268
->method('getViewId')
@@ -297,7 +296,7 @@ public function testUpdate()
297296
'getList'
298297
)->with(
299298
$lastVersionId,
300-
$lastVersionId + $defaultBatchSize
299+
$currentVersionId
301300
)->will(
302301
$this->returnValue($listId)
303302
);
@@ -327,7 +326,6 @@ public function testUpdateWithException()
327326
$currentVersionId = 3;
328327
$lastVersionId = 1;
329328
$listId = [2, 3];
330-
$defaultBatchSize = 1000;
331329

332330
$this->stateMock->expects($this->any())
333331
->method('getViewId')
@@ -360,7 +358,7 @@ public function testUpdateWithException()
360358
'getList'
361359
)->with(
362360
$lastVersionId,
363-
$lastVersionId + $defaultBatchSize
361+
$currentVersionId
364362
)->will(
365363
$this->returnValue($listId)
366364
);

lib/internal/Magento/Framework/Mview/View.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class View extends \Magento\Framework\DataObject implements ViewInterface
2121
*/
2222
const DEFAULT_BATCH_SIZE = 1000;
2323

24+
/**
25+
* Max versions to load from database at a time
26+
*/
27+
private static $maxVersionQueryBatch = 100000;
28+
2429
/**
2530
* @var string
2631
*/
@@ -272,14 +277,19 @@ public function update()
272277
try {
273278
$this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save();
274279

280+
$versionBatchSize = self::$maxVersionQueryBatch;
275281
$batchSize = isset($this->changelogBatchSize[$this->getChangelog()->getViewId()])
276282
? $this->changelogBatchSize[$this->getChangelog()->getViewId()]
277283
: self::DEFAULT_BATCH_SIZE;
278284

279-
for ($versionFrom = $lastVersionId; $versionFrom < $currentVersionId; $versionFrom += $batchSize) {
280-
$ids = $this->getChangelog()->getList($versionFrom, $versionFrom + $batchSize);
285+
for ($versionFrom = $lastVersionId; $versionFrom < $currentVersionId; $versionFrom += $versionBatchSize) {
286+
// Don't go past the current version for atomicy.
287+
$versionTo = min($currentVersionId, $versionFrom + $versionBatchSize);
288+
$ids = $this->getChangelog()->getList($versionFrom, $versionTo);
281289

282-
if (!empty($ids)) {
290+
// We run the actual indexer in batches. Chunked AFTER loading to avoid duplicates in separate chunks.
291+
$chunks = array_chunk($ids, $batchSize);
292+
foreach ($chunks as $ids) {
283293
$action->execute($ids);
284294
}
285295
}

0 commit comments

Comments
 (0)