Skip to content

Use keyset pagination instead of offset #1

@ThisIsMissEm

Description

@ThisIsMissEm

Currently Adonis's built in paginate method relies on offset pagination, which means pagination cursors aren't stable. This can cause issues in annotation collections which are frequently updated, as you'll miss items.

Keyset pagination is the solution.

Essentially instead of:

SELECT * FROM "annotations" WHERE collection_id = decode(?, 'hex') LIMIT ? OFFSET ?

We do:

SELECT * FROM "annotations" WHERE collection_id = decode(?, 'hex') AND id > ? ORDER BY id DESC LIMIT ?

It does change the pagination URLs too, from:

/annotations/781bc04ec9bd049cdfacaec4ae2026102118d13c79413246f0c88eeef6ebec4e?page=1

to:

/annotations/781bc04ec9bd049cdfacaec4ae2026102118d13c79413246f0c88eeef6ebec4e?min_id=0192e517-1e93-742d-a8bf-e8f491c570da

or

/annotations/781bc04ec9bd049cdfacaec4ae2026102118d13c79413246f0c88eeef6ebec4e?max_id=0192e517-1e93-742d-a8bf-e8f491c570da

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions