From 754f8546a6a7a6f419eec2613e9e6063828b0b2a Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Fri, 22 Apr 2016 15:17:20 -0400 Subject: [PATCH] Switched /api/v1/roles/ to a cursor paginator so we don't have to do a count() on that potentially very large result set --- awx/api/serializers.py | 9 +++++++-- awx/api/views.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 5dae65e338..ec497d97f6 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1443,8 +1443,13 @@ class RoleSerializer(BaseSerializer): class Meta: model = Role - fields = ('*', 'description', 'name') - read_only_fields = ('description', 'name') + read_only_fields = ('id', 'role_field', 'description', 'name') + + def to_representation(self, obj): + ret = super(RoleSerializer, self).to_representation(obj) + ret.pop('created') + ret.pop('modified') + return ret def get_related(self, obj): ret = super(RoleSerializer, self).get_related(obj) diff --git a/awx/api/views.py b/awx/api/views.py index 3e70cb8099..be7dcbb215 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -38,6 +38,7 @@ from rest_framework.permissions import AllowAny, IsAuthenticated from rest_framework.response import Response from rest_framework.settings import api_settings from rest_framework.views import exception_handler +from rest_framework.pagination import CursorPagination from rest_framework import status # Django REST Framework YAML @@ -3475,6 +3476,9 @@ class RoleList(ListAPIView): model = Role serializer_class = RoleSerializer permission_classes = (IsAuthenticated,) + class CursorPaginationById(CursorPagination): + ordering = 'id' + pagination_class = CursorPaginationById new_in_300 = True def get_queryset(self):