Skip to content

chunk and chunkById only works with 1000 posts count #68

@devmade

Description

@devmade

Package version

v5.0.5

Describe the bug

In ->chunk() and ->chunkById(), if posts count is anything but 1000, it stops the loop after 1000 models (or just one chunk)

For example:
Post::chunkById(100, callback) only gets 1000 posts, but
Post::chunkById(1000, callback) gets all the posts there are (4750 items)

To Reproduce

Steps to reproduce the behavior:

$counter = 0;
$set = [];

Post::chunkById(100, function ($models) use (&$counter, &$set) {
    $counter += count($models);

    foreach ($models as $model) {
        $set[] = $model->_id;
    }

    echo "Counter reached: " . $counter . "\n";

    if ($counter > 10000) {
        return false; // Stop the chunking
    }
});

$this->info("Total count: " . $counter);
$this->info("Set size: " . count($set));
$this->info("Unique IDs: " . count(array_unique($set)));

Expected behavior

Each chunk should have expected number of posts and should run until there are no more posts

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions