Refs #28459 -- Improved performance of FlatValuesListIterable.

This commit is contained in:
Sergey Fedoseev 2017-08-22 20:26:07 +05:00 committed by Tim Graham
parent 254fb8d1a4
commit 4dfd6b88d5
1 changed files with 6 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import sys
import warnings
from collections import OrderedDict, deque
from contextlib import suppress
from itertools import chain
from django.conf import settings
from django.core import exceptions
@ -145,8 +146,7 @@ class FlatValuesListIterable(BaseIterable):
def __iter__(self):
queryset = self.queryset
compiler = queryset.query.get_compiler(queryset.db)
for row in compiler.results_iter():
yield row[0]
return chain.from_iterable(compiler.results_iter())
class QuerySet:
@ -302,6 +302,9 @@ class QuerySet:
# 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):
"""
An iterator over the results from applying this QuerySet to the
@ -310,7 +313,7 @@ class QuerySet:
if chunk_size <= 0:
raise ValueError('Chunk size must be strictly positive.')
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):
"""