From f356a9a1b241bd258b953386ceb3eb5323d793da Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 11 Aug 2016 16:40:23 +0100 Subject: [PATCH] Do not re-run query for empty results with LimitOffsetPagination --- rest_framework/pagination.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 77c10337e..c54894efc 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -312,6 +312,9 @@ class LimitOffsetPagination(BasePagination): self.request = request if self.count > self.limit and self.template is not None: self.display_page_controls = True + + if self.count == 0 or self.offset > self.count: + return [] return list(queryset[self.offset:self.offset + self.limit]) def get_paginated_response(self, data):