4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
+ declare (strict_types=1 );
8
+
7
9
namespace Magento \Framework \Mview ;
8
10
9
11
use InvalidArgumentException ;
@@ -254,23 +256,7 @@ public function update()
254
256
try {
255
257
$ this ->getState ()->setStatus (View \StateInterface::STATUS_WORKING )->save ();
256
258
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 );
274
260
275
261
$ this ->getState ()->loadByView ($ this ->getId ());
276
262
$ statusToRestore = $ this ->getState ()->getStatus () === View \StateInterface::STATUS_SUSPENDED
@@ -294,6 +280,36 @@ public function update()
294
280
}
295
281
}
296
282
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
+
297
313
/**
298
314
* Suspend view updates and set version ID to changelog's end
299
315
*
0 commit comments