1
0
mirror of https://github.com/django/django.git synced 2024-12-25 02:26:12 +00:00

Avoided storing ExpressionNodes in dicts

This commit is contained in:
Anssi Kääriäinen 2012-09-30 17:50:56 +03:00
parent ab2a1773fd
commit ddd7d1af20

View File

@ -6,7 +6,7 @@ class SQLEvaluator(object):
def __init__(self, expression, query, allow_joins=True):
self.expression = expression
self.opts = query.get_meta()
self.cols = {}
self.cols = []
self.contains_aggregate = False
self.expression.prepare(self, query, allow_joins)
@ -18,11 +18,15 @@ class SQLEvaluator(object):
return self.expression.evaluate(self, qn, connection)
def relabel_aliases(self, change_map):
for node, col in self.cols.items():
new_cols = []
for node, col in self.cols:
if hasattr(col, "relabel_aliases"):
col.relabel_aliases(change_map)
new_cols.append((node, col))
else:
self.cols[node] = (change_map.get(col[0], col[0]), col[1])
new_cols.append((node,
(change_map.get(col[0], col[0]), col[1])))
self.cols = new_cols
#####################################################
# Vistor methods for initial expression preparation #
@ -41,7 +45,7 @@ class SQLEvaluator(object):
if (len(field_list) == 1 and
node.name in query.aggregate_select.keys()):
self.contains_aggregate = True
self.cols[node] = query.aggregate_select[node.name]
self.cols.append((node, query.aggregate_select[node.name]))
else:
try:
field, source, opts, join_list, last, _ = query.setup_joins(
@ -49,7 +53,7 @@ class SQLEvaluator(object):
query.get_initial_alias(), False)
col, _, join_list = query.trim_joins(source, join_list, last, False)
self.cols[node] = (join_list[-1], col)
self.cols.append((node, (join_list[-1], col)))
except FieldDoesNotExist:
raise FieldError("Cannot resolve keyword %r into field. "
"Choices are: %s" % (self.name,
@ -80,7 +84,13 @@ class SQLEvaluator(object):
return connection.ops.combine_expression(node.connector, expressions), expression_params
def evaluate_leaf(self, node, qn, connection):
col = self.cols[node]
col = None
for n, c in self.cols:
if n is node:
col = c
break
if col is None:
raise ValueError("Given node not found")
if hasattr(col, 'as_sql'):
return col.as_sql(qn, connection), ()
else: