Skip to content

Commit ba4dff7

Browse files
author
Quentin Farizon
committed
Refactor View::update
1 parent d91a3c9 commit ba4dff7

File tree

1 file changed

+33
-17
lines changed
  • lib/internal/Magento/Framework/Mview

1 file changed

+33
-17
lines changed

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Framework\Mview;
810

911
use InvalidArgumentException;
@@ -254,23 +256,7 @@ public function update()
254256
try {
255257
$this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save();
256258

257-
$versionBatchSize = self::$maxVersionQueryBatch;
258-
$batchSize = isset($this->changelogBatchSize[$this->getChangelog()->getViewId()])
259-
? $this->changelogBatchSize[$this->getChangelog()->getViewId()]
260-
: self::DEFAULT_BATCH_SIZE;
261-
262-
for ($vsFrom = $lastVersionId; $vsFrom < $currentVersionId; $vsFrom += $versionBatchSize) {
263-
// Don't go past the current version for atomicy.
264-
$versionTo = min($currentVersionId, $vsFrom + $versionBatchSize);
265-
$ids = $this->getChangelog()->getList($vsFrom, $versionTo);
266-
267-
// We run the actual indexer in batches.
268-
// Chunked AFTER loading to avoid duplicates in separate chunks.
269-
$chunks = array_chunk($ids, $batchSize);
270-
foreach ($chunks as $ids) {
271-
$action->execute($ids);
272-
}
273-
}
259+
$this->executeAction($action, $lastVersionId, $currentVersionId);
274260

275261
$this->getState()->loadByView($this->getId());
276262
$statusToRestore = $this->getState()->getStatus() === View\StateInterface::STATUS_SUSPENDED
@@ -294,6 +280,36 @@ public function update()
294280
}
295281
}
296282

283+
/**
284+
* Execute action from last version to current version, by batches
285+
*
286+
* @param ActionInterface $action
287+
* @param int $lastVersionId
288+
* @param int $currentVersionId
289+
* @return void
290+
* @throws \Exception
291+
*/
292+
private function executeAction(ActionInterface $action, int $lastVersionId, int $currentVersionId)
293+
{
294+
$versionBatchSize = self::$maxVersionQueryBatch;
295+
$batchSize = isset($this->changelogBatchSize[$this->getChangelog()->getViewId()])
296+
? $this->changelogBatchSize[$this->getChangelog()->getViewId()]
297+
: self::DEFAULT_BATCH_SIZE;
298+
299+
for ($vsFrom = $lastVersionId; $vsFrom < $currentVersionId; $vsFrom += $versionBatchSize) {
300+
// Don't go past the current version for atomicity.
301+
$versionTo = min($currentVersionId, $vsFrom + $versionBatchSize);
302+
$ids = $this->getChangelog()->getList($vsFrom, $versionTo);
303+
304+
// We run the actual indexer in batches.
305+
// Chunked AFTER loading to avoid duplicates in separate chunks.
306+
$chunks = array_chunk($ids, $batchSize);
307+
foreach ($chunks as $ids) {
308+
$action->execute($ids);
309+
}
310+
}
311+
}
312+
297313
/**
298314
* Suspend view updates and set version ID to changelog's end
299315
*

0 commit comments

Comments
 (0)