Skip to content

Commit 4ea7487

Browse files
committed
Refactor.
1 parent f1390aa commit 4ea7487

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

django_mongodb_backend/compiler.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -660,28 +660,25 @@ def get_combinator_queries(self):
660660

661661
def _get_pushable_conditions(self):
662662
def collect_pushable(expr, negated=False):
663-
if isinstance(expr, NothingNode):
663+
if expr is None or isinstance(expr, NothingNode):
664664
return {}
665665
if isinstance(expr, WhereNode):
666-
negated = negated != expr.negated
666+
negated ^= expr.negated
667667
pushable_expressions = [
668-
collect_pushable(sub_expr, negated=negated) for sub_expr in expr.children
668+
collect_pushable(sub_expr, negated=negated)
669+
for sub_expr in expr.children
670+
if sub_expr is not None
669671
]
670672
operator = expr.connector
671673
if operator == XOR:
672674
return {}
673675
if negated:
674676
operator = OR if operator == AND else AND
675677
alias_children = defaultdict(list)
676-
shared_alias = None
677-
result = {}
678678
for pe in pushable_expressions:
679-
if not shared_alias:
680-
shared_alias = set(pe)
681-
else:
682-
shared_alias &= set(pe)
683679
for alias, expressions in pe.items():
684680
alias_children[alias].append(expressions)
681+
result = {}
685682
for alias, children in alias_children.items():
686683
result[alias] = WhereNode(
687684
children=children,
@@ -690,11 +687,14 @@ def collect_pushable(expr, negated=False):
690687
)
691688
if operator == AND:
692689
return result
690+
shared_alias = (
691+
set.intersection(*(set(pe) for pe in pushable_expressions))
692+
if pushable_expressions
693+
else set()
694+
)
693695
return {k: v for k, v in result.items() if k in shared_alias}
694-
if (
695-
expr is not None
696-
and isinstance(expr.lhs, Col)
697-
and (is_constant_value(expr.rhs) or getattr(expr.rhs, "is_simple_column", False))
696+
if isinstance(expr.lhs, Col) and (
697+
is_constant_value(expr.rhs) or getattr(expr.rhs, "is_simple_column", False)
698698
):
699699
alias = expr.lhs.alias
700700
expr = WhereNode(children=[expr], negated=negated)

0 commit comments

Comments
 (0)