Skip to content

Commit

Permalink
implements batch processing on filtering parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Dec 28, 2024
1 parent 87048f4 commit e78a6f1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions classes/ilios.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class ilios {
*/
const API_BASE_PATH = '/api/v3/';

/**
* @var int The maximum number of filtering request parameters in a given API request.
*/
const MAX_FILTER_PARAMS = 250;

/**
* @var string The API access token.
*/
Expand Down Expand Up @@ -335,6 +340,16 @@ public function get(
array $filterby = [],
array $sortby = [],
): array {
// If needed, recursively call this function with smaller batch sizes of filtering parameters.
if (count($filterby) > self::MAX_FILTER_PARAMS) {
$batches = array_chunk($filterby, self::MAX_FILTER_PARAMS);
$results = [];
foreach ($batches as $batch) {
$result = $this->get($path, $key, $batch, $sortby);
$results = array_merge($results, $result);
}
return $results;
}
$this->validate_access_token($this->accesstoken);
$options = ['headers' => ['X-JWT-Authorization' => 'Token ' . $this->accesstoken]];

Expand Down

0 comments on commit e78a6f1

Please sign in to comment.