-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v4.5.2
Feature type
New functionality
Proposed functionality
Implement cursor-based pagination for REST API, similar to what we did for the GraphQL API under #21110 in v4.5.2. This entails introducing a new start query parameter as an alternative to the offset parameter. This would be used in conjunction with the limit parameter` to paginate results, e.g.
GET /api/dcim/sites/?start=1234&limit=100
Unlike offset, which passes a relative position, the start parameter identifies a numeric primary key and returns all objects with a primary key equal to or greater than that value up to the specified limit. Note that objects must be ordered by primary key (rather than their native ordering by e.g. name) for effective pagination.
Note: This was proposed under FR #9599 but no workable implementation was identified at that time. It remains to be determined whether we can identify a feasible solution for the REST API.
Use case
The current pagination approach relies on a relative offset. This struggles with very large result sets, because the offset must be calculated by scanning the entire table up to the offset position. Employing an object's unique primary key as a cursor avoids this, as we can leverage simple numeric comparison to filter for all PKs greater than or equal to a given value. Combined with the existing limit capability, this affords very efficient pagination at the cost of a fixed (and not very meaningful) ordering.
Database changes
No response
External dependencies
No response