Skip to content

Commit

Permalink
Commit suggestion from Adam
Browse files Browse the repository at this point in the history
Co-authored-by: Adam <[email protected]>
  • Loading branch information
axelerant-hardik and adam-vessey authored May 7, 2024
1 parent 13fa6cb commit 3ff98be
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions src/Commands/RebuildOaiEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,28 @@ public function rebuild(array $options = [
*/
public function rebuildBatch(int $batch_size, &$context) {
$queue = $this->queue->get('rest_oai_pmh_views_cache_cron');
$queue_total_items = $queue->numberOfItems();

// If no items are found, set the context finished and show a message.
if (!($queue_total_items > 0)) {
$context['finished'] = 1;
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['total'] = $queue->numberOfItems();
}
else {
// Setting the defaults.
if (empty($context['sandbox'])) {
$context['sandbox']['processed_items'] = 0;
$context['sandbox']['total_items'] = $queue_total_items;
}

$start = $context['sandbox']['processed_items'];
$end = $start + $batch_size;
$end = min($end, $context['sandbox']['total_items']);

// Processing the queue items.
while ($context['sandbox']['processed_items'] < $end) {
$item = $queue->claimItem();
rest_oai_pmh_process_queue($item);

$context['sandbox']['processed_items']++;
}

// Set the batch progress percentage.
$context['finished'] = $context['sandbox']['processed_items'] / $context['sandbox']['total_items'];

$item = $queue->claimItem();
if (!$item) {
// Queue exhausted; we're done. Shouldn't strictly be necessary, but we could explicitly
// set `$context['finished'] = 1;` if we wanted to.
return;
}

rest_oai_pmh_process_queue($item);

$context['sandbox']['processed_items']++;

$context['finished'] = $context['sandbox']['processed_items'] / (
// XXX: Force queue exhaustion above to terminate.
$context['sandbox']['processed_items'] >= $context['sandbox']['total_items'] ?
$context['sandbox']['processed_items'] + 1 :
$context['sandbox']['total_items']
));
}

}

0 comments on commit 3ff98be

Please sign in to comment.