Double query to retrieve a Paginator's page

8 views
Skip to first unread message

hldev

unread,
Sep 25, 2020, 9:57:20 AM9/25/20
to Django users

Paginator.page() when called for the first time will trigger the evaluation of the cached property "count", which performs a COUNT query on the database. It will generally happen every time, since a new Paginator object is made for each new request.
The problem here is that the COUNT query costs almost the same as the main query which retrieves the page's items, so in effect it's doubling the needed query.
How can I avoid that duplication?
Reply all
Reply to author
Forward
0 new messages