A Count-less Paginator for high-performance navigation
- Dominant language
- No language data
- Stars
- 188
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
### Code of Conduct
- [x] I agree to follow Django's Code of Conduct
### Feature Description
The new paginator provides a way to navigate results without performing a COUNT(*) query, instead determining the existence of a "next page" by fetching `N + 1` items.
### Problem
On large PostgreSQL or MySQL tables, `SELECT COUNT(*)` requires a full or partial index scan that scales linearly with data size. Even if the actual data fetch is fast (via indexed slicing), the Paginator is forced to wait for the count to:
- Validate the page number
- Determine if a "next" page exists
- Calculate the total number of pages for the UI
In many modern UIs (like "Infinite Scroll" or "Next/Prev" only navigation), the total page count is unnecessary and actively hurts performance.
### Request or proposal
proposal
### Additional Details
I propose adding a EfficientPaginator/LitePaginator that lives alongside `AsyncPaginator` and `BasePaginator and`:
1. Avoids the .count() call entirely.
2. Determines has_next() by attempting to fetch per_page + 1 items.
### Implementation Suggestions
```
// 1. Calculate where to start fetching in the database
// 2. Ask for exactly ONE extra item
// 3. Fetch from the database (No COUNT query needed!)
results = Database.query("SELECT * FROM table LIMIT {limit} OFFSET {offset}")
// 4. Check if we got that extra item
IF length_of(results) > items_per_page:
has_next_page = TRUE
// Remove that extra item so we only display the requested amount
ELSE:
// We got exactly the amount needed, or fewer. This is the last page.
// 5. Return the page data
RETURN results, has_next_page
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.