Description
I wonder if we can support cursor-based pagination instead of offset based.
I was hoping to get something like: Slack API Pagination
We are hoping to get a RESTful feature for this cursor-based because our micro services have been using cursor for fast lookup. It saves time not to scan though n
records in database that we don't retrieve where n
is the number of offset. I think this benefit greatly for speed. The database that use some sort of sorted table, merge tree, or B+tree can benefit greatly because cursor translate to a where clause index >= <YOUR VALUE>
which can skip data partitions where condition is not met, pruning a lot of scanning. Where as N offset means the database have to count from 0 - offset before retrieving items, wasting time on scanning N items.
I propose that:
resource.ItemList
has 1 more field calledCursor string
.Cursor
is optional. If suppose the request includes?cursor="<base64 or whatever string encoded>"
then the storer can respect this condition and fetch the database for a given cursor.
NOTE:
Cursor string
can translate to multi fields in database, let sayBase64Encoded(CreatedAt, UpdatedAt)
. This means filter out item that areCreatedAt < cursorCreatedAt
andUpdatedAt < cursorUpdatedAt