mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-03 03:43:28 +03:00
queryset.count() optimized
This commit is contained in:
parent
608af578d4
commit
46f413d8a5
|
@ -1,6 +1,7 @@
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
from django.db.models import Count
|
||||||
from graphql_relay.connection.arrayconnection import (
|
from graphql_relay.connection.arrayconnection import (
|
||||||
connection_from_array_slice,
|
connection_from_array_slice,
|
||||||
cursor_to_offset,
|
cursor_to_offset,
|
||||||
|
@ -144,7 +145,7 @@ class DjangoConnectionField(ConnectionField):
|
||||||
iterable = maybe_queryset(iterable)
|
iterable = maybe_queryset(iterable)
|
||||||
|
|
||||||
if isinstance(iterable, QuerySet):
|
if isinstance(iterable, QuerySet):
|
||||||
list_length = iterable.count()
|
list_length = iterable.aggregate(Count('pk'))['pk__count']
|
||||||
else:
|
else:
|
||||||
list_length = len(iterable)
|
list_length = len(iterable)
|
||||||
list_slice_length = (
|
list_slice_length = (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user