ash icon indicating copy to clipboard operation
ash copied to clipboard

Support a "fetch" style of keyset pagination that allows complex sorts in conjunction

Open zachdaniel opened this issue 4 years ago • 1 comments
trafficstars

Due to the filter-based implementation of keyset pagination, it cannot be used with sorts on calculations.

We could solve this problem by making the keyset only be the primary key of the record, and then fetching that value loading the calculations/aggregates that we need. If we do this we should either: 1.) make it a new pagination mode or 2.) add an option like mode: :strict | :fetch (name TBD)to pagination options.

Let me know if you're reading this and want to help implement it.

More on ash pagination: https://hexdocs.pm/ash/pagination.html#keyset-pagination

Keyset pagination currently works by taking all of the fields being sorted on and their values and building it into a binary. There are a couple potential problems with this approach, for example if someone sorted on a massive text field we may have a problem. So we want to add this alternative message for a few different reasons. By limiting the keyset to only the primary key, we have to refetch the record, including loading any calculations/aggregates that are being used in the query. Then we can build the query to fetch everything after that record.

zachdaniel avatar Jul 22 '21 20:07 zachdaniel

Before this is closed we should make sure to address #334

zachdaniel avatar May 31 '22 16:05 zachdaniel

So I've switched the underlying code to use this new fetch style. We will solve separately for the more_previous? concept in #334

zachdaniel avatar Sep 11 '22 20:09 zachdaniel

This was solved in 64b3312cb94869d3ef9b25a11658e056c7191380

zachdaniel avatar Sep 11 '22 20:09 zachdaniel

CI is failing because of this line: https://github.com/ash-project/ash/commit/64b3312cb94869d3ef9b25a11658e056c7191380#diff-dfa6f4ed74c90e5d4fda283d547d366586e690387289bcfd473e3fa5f9ace308R223

dolfinus avatar Sep 11 '22 21:09 dolfinus

Yep! Accidentally commited. Fixed now.

zachdaniel avatar Sep 11 '22 22:09 zachdaniel