mirror of https://github.com/jumpserver/jumpserver
perf: 优化 queryset count
parent
6b748e5ac5
commit
089cadeae3
|
@ -1,6 +1,13 @@
|
|||
from django.conf import settings
|
||||
from django.core.exceptions import FieldError
|
||||
from rest_framework.pagination import LimitOffsetPagination
|
||||
|
||||
|
||||
class MaxLimitOffsetPagination(LimitOffsetPagination):
|
||||
max_limit = settings.MAX_LIMIT_PER_PAGE
|
||||
|
||||
def get_count(self, queryset):
|
||||
try:
|
||||
return queryset.values_list('id').order_by().count()
|
||||
except (AttributeError, TypeError, FieldError):
|
||||
return len(queryset)
|
||||
|
|
Loading…
Reference in New Issue