Do not do SELECT count(*) FROM ... if pagination is not requested (#6098)

* Do not do `SELECT count(*) FROM ...` if pagination is not requested

* Update pagination.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
This commit is contained in:
Dmitry Mugtasimov 2021-03-09 15:06:12 +03:00 committed by GitHub
parent 750bad0a58
commit a3ae8ea77e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -376,11 +376,11 @@ class LimitOffsetPagination(BasePagination):
template = 'rest_framework/pagination/numbers.html' template = 'rest_framework/pagination/numbers.html'
def paginate_queryset(self, queryset, request, view=None): def paginate_queryset(self, queryset, request, view=None):
self.count = self.get_count(queryset)
self.limit = self.get_limit(request) self.limit = self.get_limit(request)
if self.limit is None: if self.limit is None:
return None return None
self.count = self.get_count(queryset)
self.offset = self.get_offset(request) self.offset = self.get_offset(request)
self.request = request self.request = request
if self.count > self.limit and self.template is not None: if self.count > self.limit and self.template is not None: