File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
lib/internal/Magento/Framework/Mview Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -263,7 +263,6 @@ public function testUpdate()
263
263
$ currentVersionId = 3 ;
264
264
$ lastVersionId = 1 ;
265
265
$ listId = [2 , 3 ];
266
- $ defaultBatchSize = 1000 ;
267
266
268
267
$ this ->stateMock ->expects ($ this ->any ())
269
268
->method ('getViewId ' )
@@ -297,7 +296,7 @@ public function testUpdate()
297
296
'getList '
298
297
)->with (
299
298
$ lastVersionId ,
300
- $ lastVersionId + $ defaultBatchSize
299
+ $ currentVersionId
301
300
)->will (
302
301
$ this ->returnValue ($ listId )
303
302
);
@@ -327,7 +326,6 @@ public function testUpdateWithException()
327
326
$ currentVersionId = 3 ;
328
327
$ lastVersionId = 1 ;
329
328
$ listId = [2 , 3 ];
330
- $ defaultBatchSize = 1000 ;
331
329
332
330
$ this ->stateMock ->expects ($ this ->any ())
333
331
->method ('getViewId ' )
@@ -360,7 +358,7 @@ public function testUpdateWithException()
360
358
'getList '
361
359
)->with (
362
360
$ lastVersionId ,
363
- $ lastVersionId + $ defaultBatchSize
361
+ $ currentVersionId
364
362
)->will (
365
363
$ this ->returnValue ($ listId )
366
364
);
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ class View extends \Magento\Framework\DataObject implements ViewInterface
21
21
*/
22
22
const DEFAULT_BATCH_SIZE = 1000 ;
23
23
24
+ /**
25
+ * Max versions to load from database at a time
26
+ */
27
+ private static $ maxVersionQueryBatch = 100000 ;
28
+
24
29
/**
25
30
* @var string
26
31
*/
@@ -272,14 +277,19 @@ public function update()
272
277
try {
273
278
$ this ->getState ()->setStatus (View \StateInterface::STATUS_WORKING )->save ();
274
279
280
+ $ versionBatchSize = self ::$ maxVersionQueryBatch ;
275
281
$ batchSize = isset ($ this ->changelogBatchSize [$ this ->getChangelog ()->getViewId ()])
276
282
? $ this ->changelogBatchSize [$ this ->getChangelog ()->getViewId ()]
277
283
: self ::DEFAULT_BATCH_SIZE ;
278
284
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 );
281
289
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 ) {
283
293
$ action ->execute ($ ids );
284
294
}
285
295
}
You can’t perform that action at this time.
0 commit comments