Removed use of SortedDict for query.alias_refcount

This will have a smallish impact on performance. Refs #19276.
This commit is contained in:
Anssi Kääriäinen 2012-11-11 01:59:24 +02:00
parent 538d6c0fcd
commit fe21c233d4
1 changed files with 5 additions and 5 deletions

View File

@ -103,7 +103,7 @@ class Query(object):
def __init__(self, model, where=WhereNode): def __init__(self, model, where=WhereNode):
self.model = model self.model = model
self.alias_refcount = SortedDict() self.alias_refcount = {}
# alias_map is the most important data structure regarding joins. # alias_map is the most important data structure regarding joins.
# It's used for recording which joins exist in the query and what # It's used for recording which joins exist in the query and what
# type they are. The key is the alias of the joined table (possibly # type they are. The key is the alias of the joined table (possibly
@ -845,7 +845,7 @@ class Query(object):
count. Note that after execution, the reference counts are zeroed, so count. Note that after execution, the reference counts are zeroed, so
tables added in compiler will not be seen by this method. tables added in compiler will not be seen by this method.
""" """
return len([1 for count in six.itervalues(self.alias_refcount) if count]) return len([1 for count in self.alias_refcount.values() if count])
def join(self, connection, always_create=False, exclusions=(), def join(self, connection, always_create=False, exclusions=(),
promote=False, outer_if_first=False, nullable=False, reuse=None): promote=False, outer_if_first=False, nullable=False, reuse=None):
@ -1583,9 +1583,9 @@ class Query(object):
# comparison to NULL (e.g. in # comparison to NULL (e.g. in
# Tag.objects.exclude(parent__parent__name='t1'), a tag with no parent # Tag.objects.exclude(parent__parent__name='t1'), a tag with no parent
# would otherwise be overlooked). # would otherwise be overlooked).
active_positions = [pos for (pos, count) in active_positions = len([count for count
enumerate(six.itervalues(query.alias_refcount)) if count] in query.alias_refcount.items() if count])
if active_positions[-1] > 1: if active_positions > 1:
self.add_filter(('%s__isnull' % prefix, False), negate=True, self.add_filter(('%s__isnull' % prefix, False), negate=True,
trim=True, can_reuse=can_reuse) trim=True, can_reuse=can_reuse)