Skip to content

Commit e05e46d

Browse files
author
Quentin Farizon
committed
Refactor View::update
1 parent 7ffb199 commit e05e46d

File tree

1 file changed

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

1 file changed

+31
-17
lines changed

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

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,26 +274,11 @@ public function update()
274274
$lastVersionId = (int) $this->getState()->getVersionId();
275275
$action = $this->actionFactory->get($this->getActionClass());
276276

277+
$this->executeAction($action, $lastVersionId, $currentVersionId);
278+
277279
try {
278280
$this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save();
279281

280-
$versionBatchSize = self::$maxVersionQueryBatch;
281-
$batchSize = isset($this->changelogBatchSize[$this->getChangelog()->getViewId()])
282-
? $this->changelogBatchSize[$this->getChangelog()->getViewId()]
283-
: self::DEFAULT_BATCH_SIZE;
284-
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 = array_map('intval', $this->getChangelog()->getList($versionFrom, $versionTo));
289-
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) {
293-
$action->execute($ids);
294-
}
295-
}
296-
297282
$this->getState()->loadByView($this->getId());
298283
$statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED
299284
? View\StateInterface::STATUS_SUSPENDED
@@ -317,6 +302,35 @@ public function update()
317302
}
318303
}
319304

305+
/**
306+
* Execute action from last version to current version, by batches
307+
*
308+
* @param ActionInterface $action
309+
* @param int $lastVersionId
310+
* @param int $currentVersionId
311+
* @return void
312+
* @throws \Exception
313+
*/
314+
private function executeAction(ActionInterface $action, int $lastVersionId, int $currentVersionId)
315+
{
316+
$versionBatchSize = self::$maxVersionQueryBatch;
317+
$batchSize = isset($this->changelogBatchSize[$this->getChangelog()->getViewId()])
318+
? $this->changelogBatchSize[$this->getChangelog()->getViewId()]
319+
: self::DEFAULT_BATCH_SIZE;
320+
321+
for ($versionFrom = $lastVersionId; $versionFrom < $currentVersionId; $versionFrom += $versionBatchSize) {
322+
// Don't go past the current version for atomicy.
323+
$versionTo = min($currentVersionId, $versionFrom + $versionBatchSize);
324+
$ids = array_map('intval', $this->getChangelog()->getList($versionFrom, $versionTo));
325+
326+
// We run the actual indexer in batches. Chunked AFTER loading to avoid duplicates in separate chunks.
327+
$chunks = array_chunk($ids, $batchSize);
328+
foreach ($chunks as $ids) {
329+
$action->execute($ids);
330+
}
331+
}
332+
}
333+
320334
/**
321335
* Suspend view updates and set version ID to changelog's end
322336
*

0 commit comments

Comments
 (0)