Skip to content

Commit

Permalink
Add setting for batch chunk size (#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley authored Nov 26, 2024
1 parent fcc8f6b commit db89905
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions application/src/Form/SettingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ public function init()
],
]);

$this->add([
'name' => 'batch_chunk_size',
'type' => 'number',
'options' => [
'element_group' => 'editing',
'label' => 'Batch chunk size', // @translate
'info' => 'Enter the size of each chunk of resources when batch editing and deleting.', // @translate
],
'attributes' => [
'id' => 'batch_chunk_size',
'value' => $this->settings->get('batch_chunk_size', 100),
],
]);

// Search element group

$this->add([
Expand Down
4 changes: 3 additions & 1 deletion application/src/Job/BatchDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class BatchDelete extends AbstractJob
public function perform()
{
$api = $this->getServiceLocator()->get('Omeka\ApiManager');
$settings = $this->getServiceLocator()->get('Omeka\Settings');
$resource = $this->getArg('resource');
$query = $this->getArg('query', []);
$response = $api->search($resource, $query, ['returnScalar' => 'id']);

// Batch delete the resources in chunks.
foreach (array_chunk($response->getContent(), 100) as $idsChunk) {
$batchChunkSize = $settings->get('batch_chunk_size', 100);
foreach (array_chunk($response->getContent(), $batchChunkSize) as $idsChunk) {
if ($this->shouldStop()) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion application/src/Job/BatchUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class BatchUpdate extends AbstractJob
public function perform()
{
$api = $this->getServiceLocator()->get('Omeka\ApiManager');
$settings = $this->getServiceLocator()->get('Omeka\Settings');

$resource = $this->getArg('resource');
$query = $this->getArg('query', []);
Expand All @@ -16,7 +17,8 @@ public function perform()
$response = $api->search($resource, $query, ['returnScalar' => 'id']);

// Batch update the resources in chunks.
foreach (array_chunk($response->getContent(), 100) as $idsChunk) {
$batchChunkSize = $settings->get('batch_chunk_size', 100);
foreach (array_chunk($response->getContent(), $batchChunkSize) as $idsChunk) {
if ($this->shouldStop()) {
return;
}
Expand Down

0 comments on commit db89905

Please sign in to comment.