@@ -46,6 +46,21 @@ class View extends \Magento\Framework\DataObject implements ViewInterface
46
46
*/
47
47
protected $ state ;
48
48
49
+ /**
50
+ * @var array
51
+ */
52
+ protected $ changelogBatchSize = [
53
+ 'default_size ' => 1000 ,
54
+ 'catalog_category_product ' => 1000 ,
55
+ 'catalog_product_category ' => 1000 ,
56
+ 'catalog_product_price ' => 1000 ,
57
+ 'catalog_product_attribute ' => 1000 ,
58
+ 'cataloginventory_stock ' => 1000 ,
59
+ 'catalogrule_rule ' => 1000 ,
60
+ 'catalogrule_product ' => 1000 ,
61
+ 'catalogsearch_fulltext ' => 1000 ,
62
+ ];
63
+
49
64
/**
50
65
* @param ConfigInterface $config
51
66
* @param ActionFactory $actionFactory
@@ -253,26 +268,36 @@ public function update()
253
268
} catch (ChangelogTableNotExistsException $ e ) {
254
269
return ;
255
270
}
256
- $ lastVersionId = $ this ->getState ()->getVersionId ();
257
- $ ids = $ this ->getChangelog ()-> getList ( $ lastVersionId , $ currentVersionId );
258
- if ( $ ids ) {
259
- $ action = $ this -> actionFactory -> get ( $ this -> getActionClass ());
271
+ $ lastVersionId = ( int ) $ this ->getState ()->getVersionId ();
272
+ $ action = $ this ->actionFactory -> get ( $ this -> getActionClass () );
273
+
274
+ try {
260
275
$ this ->getState ()->setStatus (View \StateInterface::STATUS_WORKING )->save ();
261
- try {
262
- $ action ->execute ($ ids );
263
- $ this ->getState ()->loadByView ($ this ->getId ());
264
- $ statusToRestore = $ this ->getState ()->getStatus () == View \StateInterface::STATUS_SUSPENDED
265
- ? View \StateInterface::STATUS_SUSPENDED
266
- : View \StateInterface::STATUS_IDLE ;
267
- $ this ->getState ()->setVersionId ($ currentVersionId )->setStatus ($ statusToRestore )->save ();
268
- } catch (\Exception $ exception ) {
269
- $ this ->getState ()->loadByView ($ this ->getId ());
270
- $ statusToRestore = $ this ->getState ()->getStatus () == View \StateInterface::STATUS_SUSPENDED
271
- ? View \StateInterface::STATUS_SUSPENDED
272
- : View \StateInterface::STATUS_IDLE ;
273
- $ this ->getState ()->setStatus ($ statusToRestore )->save ();
274
- throw $ exception ;
276
+
277
+ $ batchSize = isset ($ this ->changelogBatchSize [$ this ->getChangelog ()->getViewId ()])
278
+ ? $ this ->changelogBatchSize [$ this ->getChangelog ()->getViewId ()]
279
+ : $ this ->changelogBatchSize ['default_size ' ];
280
+
281
+ for ($ versionFrom = $ lastVersionId ; $ versionFrom < $ currentVersionId ; $ versionFrom += $ batchSize ) {
282
+ $ ids = $ this ->getChangelog ()->getList ($ versionFrom , $ versionFrom + $ batchSize );
283
+
284
+ if (!empty ($ ids )) {
285
+ $ action ->execute ($ ids );
286
+ }
275
287
}
288
+
289
+ $ this ->getState ()->loadByView ($ this ->getId ());
290
+ $ statusToRestore = $ this ->getState ()->getStatus () == View \StateInterface::STATUS_SUSPENDED
291
+ ? View \StateInterface::STATUS_SUSPENDED
292
+ : View \StateInterface::STATUS_IDLE ;
293
+ $ this ->getState ()->setVersionId ($ currentVersionId )->setStatus ($ statusToRestore )->save ();
294
+ } catch (\Exception $ exception ) {
295
+ $ this ->getState ()->loadByView ($ this ->getId ());
296
+ $ statusToRestore = $ this ->getState ()->getStatus () == View \StateInterface::STATUS_SUSPENDED
297
+ ? View \StateInterface::STATUS_SUSPENDED
298
+ : View \StateInterface::STATUS_IDLE ;
299
+ $ this ->getState ()->setStatus ($ statusToRestore )->save ();
300
+ throw $ exception ;
276
301
}
277
302
}
278
303
}
0 commit comments