@@ -53,6 +53,11 @@ class Gc extends Component
53
53
*/
54
54
public const EVENT_RUN = 'run ' ;
55
55
56
+ /**
57
+ * @var int The number of items that should be deleted in a single batch.
58
+ */
59
+ private const CHUNK_SIZE = 10000 ;
60
+
56
61
/**
57
62
* @var int the probability (parts per million) that garbage collection (GC) should be performed
58
63
* on a request. Defaults to 10, meaning 0.001% chance.
@@ -254,7 +259,9 @@ public function hardDeleteElements(): void
254
259
->column ();
255
260
256
261
if (!empty ($ ids )) {
257
- Db::delete (Table::ELEMENTS , ['id ' => $ ids ]);
262
+ foreach (array_chunk ($ ids , self ::CHUNK_SIZE ) as $ idsChunk ) {
263
+ Db::delete (Table::ELEMENTS , ['id ' => $ idsChunk ]);
264
+ }
258
265
}
259
266
}
260
267
@@ -308,7 +315,9 @@ public function deletePartialElements(string $elementType, string $table, string
308
315
->column ();
309
316
310
317
if (!empty ($ ids )) {
311
- Db::delete (Table::ELEMENTS , ['id ' => $ ids ]);
318
+ foreach (array_chunk ($ ids , self ::CHUNK_SIZE ) as $ idsChunk ) {
319
+ Db::delete (Table::ELEMENTS , ['id ' => $ idsChunk ]);
320
+ }
312
321
}
313
322
314
323
$ this ->_stdout ("done \n" , Console::FG_GREEN );
@@ -448,7 +457,9 @@ private function _deleteUnsupportedSiteEntries(): void
448
457
}
449
458
450
459
if (!empty ($ deleteIds )) {
451
- Db::delete (Table::ELEMENTS_SITES , ['id ' => $ deleteIds ]);
460
+ foreach (array_chunk ($ deleteIds , self ::CHUNK_SIZE ) as $ deleteIdsChunk ) {
461
+ Db::delete (Table::ELEMENTS_SITES , ['id ' => $ deleteIdsChunk ]);
462
+ }
452
463
}
453
464
454
465
$ this ->_stdout ("done \n" , Console::FG_GREEN );
@@ -470,7 +481,9 @@ private function _deleteOrphanedDraftsAndRevisions(): void
470
481
->column ();
471
482
472
483
if (!empty ($ ids )) {
473
- Db::delete ($ table , ['id ' => $ ids ]);
484
+ foreach (array_chunk ($ ids , self ::CHUNK_SIZE ) as $ idsChunk ) {
485
+ Db::delete ($ table , ['id ' => $ idsChunk ]);
486
+ }
474
487
}
475
488
}
476
489
@@ -496,7 +509,9 @@ private function _deleteOrphanedRelations(): void
496
509
->column ();
497
510
498
511
if (!empty ($ ids )) {
499
- Db::delete (Table::RELATIONS , ['id ' => $ ids ]);
512
+ foreach (array_chunk ($ ids , self ::CHUNK_SIZE ) as $ idsChunk ) {
513
+ Db::delete (Table::RELATIONS , ['id ' => $ idsChunk ]);
514
+ }
500
515
}
501
516
502
517
$ this ->_stdout ("done \n" , Console::FG_GREEN );
@@ -518,7 +533,9 @@ private function _deleteOrphanedStructureElements(): void
518
533
->column ();
519
534
520
535
if (!empty ($ ids )) {
521
- Db::delete (Table::STRUCTUREELEMENTS , ['id ' => $ ids ]);
536
+ foreach (array_chunk ($ ids , self ::CHUNK_SIZE ) as $ idsChunk ) {
537
+ Db::delete (Table::STRUCTUREELEMENTS , ['id ' => $ idsChunk ]);
538
+ }
522
539
}
523
540
524
541
$ this ->_stdout ("done \n" , Console::FG_GREEN );
@@ -636,7 +653,9 @@ public function deleteOrphanedFieldLayouts(string $elementType, string $table, s
636
653
->column ();
637
654
638
655
if (!empty ($ ids )) {
639
- Db::delete (Table::FIELDLAYOUTS , ['id ' => $ ids ]);
656
+ foreach (array_chunk ($ ids , self ::CHUNK_SIZE ) as $ idsChunk ) {
657
+ Db::delete (Table::FIELDLAYOUTS , ['id ' => $ idsChunk ]);
658
+ }
640
659
}
641
660
642
661
$ this ->_stdout ("done \n" , Console::FG_GREEN );
0 commit comments