laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Database] Improvements to the pagination without shifts (e.g. when records are skipped/revisited in next pages due to updates in previous pages) #2537

Open jonasraoni opened 3 years ago

jonasraoni commented 3 years ago

Problem

Right now there are methods that provide this feature, such as the forPageAfterId, forPageBeforeId and chunkById, but I had issues with them:

chunkById use case:

I'm using an open-source library that processes tasks in parallel, after feeding an initial set of data to it, I can call a $pool->wait($callback) which internally is a while(!$finished) callback(...) sending updates about the processing... Whenever a task is finished, I want to feed in more data, and it would be great to use the chunkById, but:

Solution

jonasraoni commented 3 years ago

If the idea is welcome I can create a PR, I already have a working code that I've written to fix my issues (a kind of chunkById that uses a generator to pass through the pages and supports multiple columns + variable sorting).

jonasraoni commented 3 years ago

In case someone has the same needs as me, I've created an extension package for myself with the features I needed, I hope it will become deprecated later 👀 Package: https://packagist.org/packages/jonasraoni/query-builder-extensions Repository: https://github.com/jonasraoni/query-builder-extensions