@@ -274,26 +274,11 @@ public function update()
274
274
$ lastVersionId = (int ) $ this ->getState ()->getVersionId ();
275
275
$ action = $ this ->actionFactory ->get ($ this ->getActionClass ());
276
276
277
+ $ this ->executeAction ($ action , $ lastVersionId , $ currentVersionId );
278
+
277
279
try {
278
280
$ this ->getState ()->setStatus (View \StateInterface::STATUS_WORKING )->save ();
279
281
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
-
297
282
$ this ->getState ()->loadByView ($ this ->getId ());
298
283
$ statusToRestore = $ this ->getState ()->getStatus () == View \StateInterface::STATUS_SUSPENDED
299
284
? View \StateInterface::STATUS_SUSPENDED
@@ -317,6 +302,35 @@ public function update()
317
302
}
318
303
}
319
304
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
+
320
334
/**
321
335
* Suspend view updates and set version ID to changelog's end
322
336
*
0 commit comments