Skip to content

Commit

Permalink
Query - Chunked - Resolved infinite loop when start chunk > 1 (#477)
Browse files Browse the repository at this point in the history
Resolved an issue when the start chunks value was > 1 an infinite loop would be created as handled messages would always be less than available messages when chunks are skipped.

Added more safety around input arguments, forcing minimums of 1 for both $chunk_size and $start_chunk.
  • Loading branch information
NeekTheNook authored Apr 11, 2024
1 parent e5e8eb0 commit 61e0f1a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,14 @@ public function get(): MessageCollection {
* @throws ResponseException
*/
public function chunked(callable $callback, int $chunk_size = 10, int $start_chunk = 1): void {
$start_chunk = max($start_chunk,1);
$chunk_size = max($chunk_size,1);
$skipped_messages_count = $chunk_size * ($start_chunk-1);

$available_messages = $this->search();
if (($available_messages_count = $available_messages->count()) > 0) {
$available_messages_count = max($available_messages->count() - $skipped_messages_count,0);

if ($available_messages_count > 0) {
$old_limit = $this->limit;
$old_page = $this->page;

Expand Down

0 comments on commit 61e0f1a

Please sign in to comment.