mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Refs #28459 -- Improved performance of FlatValuesListIterable.
This commit is contained in:
parent
254fb8d1a4
commit
4dfd6b88d5
@ -8,6 +8,7 @@ import sys
|
|||||||
import warnings
|
import warnings
|
||||||
from collections import OrderedDict, deque
|
from collections import OrderedDict, deque
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import exceptions
|
from django.core import exceptions
|
||||||
@ -145,8 +146,7 @@ class FlatValuesListIterable(BaseIterable):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
queryset = self.queryset
|
queryset = self.queryset
|
||||||
compiler = queryset.query.get_compiler(queryset.db)
|
compiler = queryset.query.get_compiler(queryset.db)
|
||||||
for row in compiler.results_iter():
|
return chain.from_iterable(compiler.results_iter())
|
||||||
yield row[0]
|
|
||||||
|
|
||||||
|
|
||||||
class QuerySet:
|
class QuerySet:
|
||||||
@ -302,6 +302,9 @@ class QuerySet:
|
|||||||
# METHODS THAT DO DATABASE QUERIES #
|
# METHODS THAT DO DATABASE QUERIES #
|
||||||
####################################
|
####################################
|
||||||
|
|
||||||
|
def _iterator(self, use_chunked_fetch, chunk_size):
|
||||||
|
yield from self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size)
|
||||||
|
|
||||||
def iterator(self, chunk_size=2000):
|
def iterator(self, chunk_size=2000):
|
||||||
"""
|
"""
|
||||||
An iterator over the results from applying this QuerySet to the
|
An iterator over the results from applying this QuerySet to the
|
||||||
@ -310,7 +313,7 @@ class QuerySet:
|
|||||||
if chunk_size <= 0:
|
if chunk_size <= 0:
|
||||||
raise ValueError('Chunk size must be strictly positive.')
|
raise ValueError('Chunk size must be strictly positive.')
|
||||||
use_chunked_fetch = not connections[self.db].settings_dict.get('DISABLE_SERVER_SIDE_CURSORS')
|
use_chunked_fetch = not connections[self.db].settings_dict.get('DISABLE_SERVER_SIDE_CURSORS')
|
||||||
return iter(self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size))
|
return self._iterator(use_chunked_fetch, chunk_size)
|
||||||
|
|
||||||
def aggregate(self, *args, **kwargs):
|
def aggregate(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user