Skip to content

Commit

Permalink
Fix for code incorrectly assuming you have at least 2x pageSize amoun…
Browse files Browse the repository at this point in the history
…t of reviews (#6)
  • Loading branch information
Jade-GG authored Aug 2, 2023
1 parent e82013e commit 7a86b1e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Actions/HarvestReviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,20 @@ public function harvest(): void

$total = $firstResponse->json('count')['total'];

$responses = Http::pool(function (Pool $pool) use ($total, $pageSize, $auth) {
foreach (range($pageSize, $total, $pageSize) as $page) {
$pools[] = $pool->withHeaders($auth)->get(config('feedback-company.api_url') . '/review', [
'limit' => $pageSize,
'start' => $page,
]);
}
return $pools;
});
if($total > $pageSize) {
$responses = Http::pool(function (Pool $pool) use ($total, $pageSize, $auth) {
$pageRange = $total > $pageSize * 2 ? range($pageSize, $total, $pageSize) : [ $pageSize ];
foreach ($pageRange as $page) {
$pools[] = $pool->withHeaders($auth)->get(config('feedback-company.api_url') . '/review', [
'limit' => $pageSize,
'start' => $page,
]);
}
return $pools;
});
}

foreach(array_merge([$firstResponse], $responses) as $response) {
foreach(array_merge([$firstResponse], $responses ?? []) as $response) {
$this->saveReviews($response->json('reviews'));
}

Expand Down

0 comments on commit 7a86b1e

Please sign in to comment.