Skip to content

Commit 07b5153

Browse files
committed
Update CHANGELOG.md
1 parent 86ae215 commit 07b5153

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Changed
1717

18+
- Improvement in `Redmine\Client\AbstractApi::retrieveData()` by using `total_count` from redmine response to avoid unnecessary http requests.
1819
- Behaviour-driven tests are run against Redmine 6.0.2, 5.1.4, 5.0.10.
1920

2021
### Deprecated

src/Redmine/Api/AbstractApi.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,16 @@ protected function retrieveData(string $endpoint, array $params = []): array
320320

321321
$returnData = [];
322322

323+
// Redmine max limit is 100,
324+
// @see https://www.redmine.org/projects/redmine/wiki/Rest_api#Collection-resources-and-pagination
325+
$redmineLimit = 100;
323326
$requestedLimit = $remaininglimit = $params['limit'];
324327
$offset = $params['offset'];
325328

326329
while ($remaininglimit > 0) {
327-
if ($remaininglimit > 100) {
328-
$realLimit = 100;
329-
$remaininglimit -= 100;
330+
if ($remaininglimit > $redmineLimit) {
331+
$realLimit = $redmineLimit;
332+
$remaininglimit -= $redmineLimit;
330333
} else {
331334
$realLimit = $remaininglimit;
332335
$remaininglimit = 0;
@@ -347,13 +350,13 @@ protected function retrieveData(string $endpoint, array $params = []): array
347350
// After the first request we know the total_count for this endpoint
348351
// so lets use the total_count to correct $requestedLimit to save us
349352
// from making unnecessary requests
350-
// e.g. total_count = 5; $requestedLimit = 500 will make only 1 request instead of 5
353+
// e.g. total_count = 5 and $requestedLimit = 500 will make only 1 request instead of 2
351354
if (isset($newDataSet['total_count']) && $newDataSet['total_count'] < $requestedLimit) {
352355
$requestedLimit = $remaininglimit = (int) $newDataSet['total_count'];
353356

354-
if ($remaininglimit > 100) {
355-
$realLimit = 100;
356-
$remaininglimit -= 100;
357+
if ($remaininglimit > $redmineLimit) {
358+
$realLimit = $redmineLimit;
359+
$remaininglimit -= $redmineLimit;
357360
} else {
358361
$realLimit = $remaininglimit;
359362
$remaininglimit = 0;

0 commit comments

Comments
 (0)