summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2013-08-21 14:25:19 +0300
committerAnssi Kääriäinen <anssi.kaariainen@thl.fi>2013-09-14 20:52:17 +0300
commitff723d894d9272ea721d1996432ffc806c2b8180 (patch)
treed1934446e13c0d29d7aecfeb0c70b7f4e220f07e /django/db/models/sql/compiler.py
parent886bb9d8780303b4c8f45c55e0ac0a6b644b73af (diff)
Fixed #20950 -- Instantiate OrderedDict() only when needed
The use of OrderedDict (even an empty one) was surprisingly slow. By initializing OrderedDict only when needed it is possible to save non-trivial amount of computing time (Model.save() is around 30% faster for example). This commit targetted sql.Query only, there are likely other places which could use similar optimizations.
Diffstat (limited to 'django/db/models/sql/compiler.py')
-rw-r--r--django/db/models/sql/compiler.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 1c6e80b538..c42149e45a 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -391,7 +391,7 @@ class SQLCompiler(object):
if not distinct or elt in select_aliases:
result.append('%s %s' % (elt, order))
group_by.append((elt, []))
- elif get_order_dir(field)[0] not in self.query.extra:
+ elif not self.query._extra or get_order_dir(field)[0] not in self.query._extra:
# 'col' is of the form 'field' or 'field1__field2' or
# '-field1__field2__field', etc.
for table, cols, order in self.find_ordering_name(field,
@@ -987,7 +987,7 @@ class SQLUpdateCompiler(SQLCompiler):
# We need to use a sub-select in the where clause to filter on things
# from other tables.
query = self.query.clone(klass=Query)
- query.extra = {}
+ query._extra = {}
query.select = []
query.add_fields([query.get_meta().pk.name])
# Recheck the count - it is possible that fiddling with the select