Refs #28459 -- Improved performance of SQLCompiler.apply_converters().

This commit is contained in:
Sergey Fedoseev 2017-08-24 01:26:24 +05:00 committed by Tim Graham
parent 4302167939
commit dca67bb2c2
2 changed files with 7 additions and 7 deletions

View File

@ -119,7 +119,6 @@ class ValuesListIterable(BaseIterable):
query = queryset.query
compiler = query.get_compiler(queryset.db)
results = compiler.results_iter()
if queryset._fields:
field_names = list(query.values_select)
extra_names = list(query.extra_select)
@ -133,8 +132,8 @@ class ValuesListIterable(BaseIterable):
# Reorder according to fields.
index_map = {name: idx for idx, name in enumerate(names)}
rowfactory = operator.itemgetter(*[index_map[f] for f in fields])
results = map(rowfactory, results)
return results
return map(rowfactory, compiler.results_iter())
return compiler.results_iter(tuple_expected=True)
class FlatValuesListIterable(BaseIterable):

View File

@ -942,16 +942,15 @@ class SQLCompiler:
def apply_converters(self, rows, converters):
connection = self.connection
converters = list(converters.items())
for row in rows:
row = list(row)
for row in map(list, rows):
for pos, (convs, expression) in converters:
value = row[pos]
for converter in convs:
value = converter(value, expression, connection)
row[pos] = value
yield tuple(row)
yield row
def results_iter(self, results=None):
def results_iter(self, results=None, tuple_expected=False):
"""Return an iterator over the results from executing this query."""
if results is None:
results = self.execute_sql(MULTI)
@ -960,6 +959,8 @@ class SQLCompiler:
rows = chain.from_iterable(results)
if converters:
rows = self.apply_converters(rows, converters)
if tuple_expected:
rows = map(tuple, rows)
return rows
def has_results(self):