feature: Add events pagination #306
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds cursor-based pagination for events, designed for a dynamic event stream where new events may continuously appear.
The API is intended for practical frontend usage with infinite scrolling and avoids issues typical for offset-based pagination (duplicates, gaps, unstable ordering).
Pagination approach
Instead of offsets, the API uses a composite cursor based on the last item of the previous page.
Each page response returns:
{ "limit": 25, "has_more": true, "next_cursor": "base64(...)" }The
next_cursorencodes a(timestamp, uuid)pair.On the next request, the server returns events strictly after this pair, ordered by:
This guarantees stable ordering and deterministic pagination, even when timestamps are equal.
The cursor is transferred as Base64 for simplicity and to prevent client-side modification.
Server-side changes
/api/eventsand/api/events/previewwith cursor-based pagination(backward compatibility preserved)
/api/events/type-countsendpoint to return the current number of events per typetimestamp; since the column is stored as string, casting is used:Result
The server now provides a stable and scalable pagination mechanism suitable for infinite scrolling and large, continuously growing event streams.