mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-06-21 20:47:31 +00:00
perf: 优化 queryset count
This commit is contained in:
parent
6b748e5ac5
commit
089cadeae3
@ -1,6 +1,13 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import FieldError
|
||||||
from rest_framework.pagination import LimitOffsetPagination
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
|
|
||||||
|
|
||||||
class MaxLimitOffsetPagination(LimitOffsetPagination):
|
class MaxLimitOffsetPagination(LimitOffsetPagination):
|
||||||
max_limit = settings.MAX_LIMIT_PER_PAGE
|
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
Block a user