Skip to content

Commit 92041aa

Browse files
authored
Merge pull request #60 from picqer/PIC-4157-perf
perf: Moved `array_merge` out of the loop when paginating results
2 parents a5ae609 + eb2dce6 commit 92041aa

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
.idea
13
composer.phar
24
composer.lock
3-
vendor/
5+
vendor/

src/Picqer/Carriers/SendCloud/Query/FindAll.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public function all($params = [], ?int $maxPages = 1): array
2121
while (true) {
2222
$result = $this->connection()->get($this->url, $params);
2323

24-
$allRecords = array_merge($allRecords, $this->collectionFromResult($result));
24+
$allRecords[] = $this->collectionFromResult($result);
2525

2626
if (! empty($result['next'])) {
2727
// Get the querystring params from the next url, so we can retrieve the next page
28-
$params = parse_url($result['next'], PHP_URL_QUERY);
28+
$params = \parse_url($result['next'], PHP_URL_QUERY);
2929
} else {
3030
// If no next page is found, all records are complete
3131
break;
@@ -34,12 +34,12 @@ public function all($params = [], ?int $maxPages = 1): array
3434
$pages++;
3535

3636
// If max pages is set and reached, also stop the loop
37-
if (! is_null($maxPages) && $pages >= $maxPages) {
37+
if (null !== $maxPages && $pages >= $maxPages) {
3838
break;
3939
}
4040
}
4141

42-
return $allRecords;
42+
return \array_merge(...$allRecords);
4343
}
4444

4545
public function collectionFromResult($result): array

0 commit comments

Comments
 (0)