Skip to content

Add support of cursor pagination #12061

Open
@seb-jean

Description

@seb-jean

Feature Request

Context

The current pagination system likely relies on offset-based pagination (e.g., using LIMIT and OFFSET). While this approach works well in simple scenarios, it comes with several drawbacks when dealing with large datasets.

Limitations of Offset-Based Pagination

  • Performance issues: The larger the OFFSET, the slower the query becomes, as the database must skip an increasing number of rows.
  • Inconsistent results: When data is inserted or deleted between two requests, items may be skipped or duplicated.

What is Cursor-Based Pagination?

Cursor-based pagination is a way to load data one page at a time by remembering where you stopped.
Instead of saying “skip the first 20 items” like offset-based pagination does, you say “start from this specific item” using a cursor.
The cursor is an encoded string containing the location that the next paginated query should start paginating. When you load the next page, you ask the system to give you the items that come after:

https://127.0.0.1:8000/users?cursor=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEwIn0.S_thQX0fWisKG8y6IfsiVW9vQdxwWQHWyjWGDiEDTF0

Below is an example of a query between offset pagination and cursor pagination:

# Offset Pagination
SELECT * FROM users ORDER BY id ASC LIMIT 10 OFFSET 10;
 
# Cursor Pagination
SELECT * FROM users WHERE id > 10 ORDER BY id ASC LIMIT 10;

Implementations In other frameworks

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions