1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 18:21:12 +03:00

Switched /api/v1/roles/ to a cursor paginator so we don't have to do a count() on that potentially very large result set

This commit is contained in:
Akita Noek 2016-04-22 15:17:20 -04:00
parent 6250d9f7e7
commit 754f8546a6
2 changed files with 11 additions and 2 deletions

View File

@ -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)

View File

@ -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):