summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2017-06-01 16:56:51 -0400
committerTim Graham <timograham@gmail.com>2017-06-01 17:50:41 -0400
commitedee5a8de6afb34a9247de2bb73ab66397a6e573 (patch)
treee306f62cdbfc1e28ffb119bdbd7870a138e91dd9 /django/db/models/sql
parentbf50ae821021c4f7cd608d2bd1f2dfff98f3ceb9 (diff)
Fixed #27639 -- Added chunk_size parameter to QuerySet.iterator().
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 5c7b5b7f51..f81861ddba 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -883,7 +883,7 @@ class SQLCompiler:
self.query.set_extra_mask(['a'])
return bool(self.execute_sql(SINGLE))
- def execute_sql(self, result_type=MULTI, chunked_fetch=False):
+ def execute_sql(self, result_type=MULTI, chunked_fetch=False, chunk_size=GET_ITERATOR_CHUNK_SIZE):
"""
Run the query against the database and return the result(s). The
return value is a single data item if result_type is SINGLE, or an
@@ -937,7 +937,8 @@ class SQLCompiler:
result = cursor_iter(
cursor, self.connection.features.empty_fetchmany_value,
- self.col_count
+ self.col_count,
+ chunk_size,
)
if not chunked_fetch and not self.connection.features.can_use_chunked_reads:
try:
@@ -1298,14 +1299,13 @@ class SQLAggregateCompiler(SQLCompiler):
return sql, params
-def cursor_iter(cursor, sentinel, col_count):
+def cursor_iter(cursor, sentinel, col_count, itersize):
"""
Yield blocks of rows from a cursor and ensure the cursor is closed when
done.
"""
try:
- for rows in iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
- sentinel):
+ for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
yield [r[0:col_count] for r in rows]
finally:
cursor.close()