by j_s · 9y ago · 0 comments
--
The hall of fame of frameworks that do support keyset pagination is rather short:
jOOQ — Java Object Oriented Querying. Docs.
Ruby order_query
Django (Python) chunkator
Django Infinite Scroll Pagination.
SQL Alchemy sqlakeyset.
blaze-persistence — a rich Criteria API for JPA providers
Perl DBIx::Class::Wrapper
How would you implement a deep pagination like "go to page 107" unless you can derive page 107 from your order criteria?
Imagine a large forum topic. The user is just seeking through time. A deep pagination here is when the user knows what they're searching for is more than 1 page away.
The user would have to know a snippet of text or an explicit date range for your search box to help, so what about all the times they don't or if their filters are insufficient? This is why forums have both deep pagination and a search box.
It would be cruel to make the user paginate one page at a time just like it'd be unbearable if Youtube didn't let you jump 10 minutes at a time.
Obviously not every pagination needs deep pagination, but that's between you and your users, and it's what came to mind when I read that article.
What's the use case for that?
You wouldn't. Keyset pagination forces the user to do the exact same thing people complain about you doing to the database. Want page 10 of results? Too bad, enjoy running through pages 1-9 and throwing them away. Except now everything is even slower because it's users talking to the service, not the service talking to the db.
There are plenty of use cases where that's a perfectly acceptable trade-off, or an annoying-but-necessary trade-off, but the people all up in a froth over the inefficiency of limit/offset seem to regularly fail to realize that they're advocating for a database performance solution with implications that reach all the way out to the UI/UX level.
At a minimum, I see very little in the way of acknowledgement of this factor.
For example, you could have a background process that slowly paginates through the table and saves off the page boundaries, which you can then use for jumping into. They will always be a bit off especially near the middle of the table, but that's probably okay.
There's lots of ways to do this fuzzy jumping that don't involve scanning the full table synchronously.
Second, you can just perform an indirection through offset (+ limit = 1).
That said, if users were doing this in my software I'd definitely be looking at how I can improve their workflow.
https://github.com/chanks/sequel-seek-pagination
I used it just this week to write a Relay Connection paginator for graphql-ruby and Sequel/Postgres. It uses keyset pagination to reliably avoid skipping items and maintain consistent query times.
Backwards pagination was a bit tricky since that’s not natively supported by sequel-seek-pagination. Basically I had to reverse the list order and then filter with the cursor values to get the last N items in a subquery, then reverse that list again to get back the desired sort order.
When I notice, I add/update this list.
I'll check those mentioned in the reply's and add them if the seem to be right.
I would recommend adding some sort of a 'last updated' type thing at the bottom of the article, along with a note that you update near that list.
As for the update marker, I've just added an "updated" date to next the the publishing date in the breadcrumb.