From 1e5890aeb4e5b724d42ada262d6bf6b4b480332e Mon Sep 17 00:00:00 2001 From: Chris O'Dell Date: Mon, 18 Nov 2019 14:23:39 +0000 Subject: [PATCH] Increase the page size for users to 500 by default This is to reduce the number of calls needed to get all of the users --- response/core/util.py | 7 +++++++ response/core/views.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/response/core/util.py b/response/core/util.py index cd1f5bde..110f9c37 100644 --- a/response/core/util.py +++ b/response/core/util.py @@ -1,6 +1,7 @@ import bleach import bleach_whitelist from django.conf import settings +from rest_framework.pagination import PageNumberPagination def sanitize(string): @@ -14,3 +15,9 @@ def sanitize(string): ) return string + + +class LargeResultsSetPagination(PageNumberPagination): + page_size = 500 + max_page_size = 1000 + page_size_query_param = "page_size" diff --git a/response/core/views.py b/response/core/views.py index 349315c1..7c884ccc 100644 --- a/response/core/views.py +++ b/response/core/views.py @@ -8,11 +8,14 @@ from response.core.models.incident import Incident from response.core.models.timeline import TimelineEvent from response.core.models.user_external import ExternalUser +from response.core.util import LargeResultsSetPagination class ExternalUserViewSet(viewsets.ReadOnlyModelViewSet): queryset = ExternalUser.objects.all() serializer_class = serializers.ExternalUserSerializer + # Set page size to 1000 + pagination_class = LargeResultsSetPagination class ActionViewSet(viewsets.ModelViewSet):