8

How do you folks handle your pagination at backend?

I was initially using skip and limit. But that is prone to error.
Then I thought about using last sent items id and using its created_at time and fetching rows/documents after that. But that too is prone to error ( more than one can have same timestamp) hence either having data repeats or data That gets missed.

What is your goto strategy for pagination?

Comments
  • 0
    I like the way wikidata does it. You request X items after Y where Y is the id of the item you saw last
  • 1
    @ChappIO but that would need a sequential Id field rich ? (I am using uuid)
  • 1
    @theElectron that would definitely make it easier yes. Then again, any good pagination solution will require some sort of implementation
  • 1
    @theElectron there often are some sequential uuid available and if not you could add an identity column just for sorting and pagination.

    If you need pagination on random sort order and cannot keep a snapshot, there probably are no solution that completely avoids occasional reappearance or lost rows depending on which is more damaging.
  • 1
    Sorting by _id in mongodb is quick and guarantees order of insertion of elements. You can use that and limit
  • 1
    @sagar13 you right ;)

    Missed the mongodb tag, yes mongodb uids are sequential since they include the current date, time, a machine specific counter and if I remember correctly parts of the mac address yo guarantee uniqueness between machines.
  • 0
    @Voxera didn't know about the machine uniqueness thing.. that's cool
  • 0
    @sagar13 yes that's useful. But we have been using parse framework(that's one abomination in face of god) And that mutherfucker manages its own _I'd depriving me of that happiness too :/
Add Comment