Skip to content

Commit

Permalink
Optimized Case.as_sql() default compilation.
Browse files Browse the repository at this point in the history
Moving compiler.compile(self.default) to the else clause avoids
the call when it's unneeded in the FullResultSet case.
  • Loading branch information
timgraham authored and sarahboyce committed Jul 11, 2024
1 parent 7264d7f commit b2fec1f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/db/models/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,6 @@ def as_sql(
template_params = {**self.extra, **extra_context}
case_parts = []
sql_params = []
default_sql, default_params = compiler.compile(self.default)
for case in self.cases:
try:
case_sql, case_params = compiler.compile(case)
Expand All @@ -1624,6 +1623,8 @@ def as_sql(
break
case_parts.append(case_sql)
sql_params.extend(case_params)
else:
default_sql, default_params = compiler.compile(self.default)
if not case_parts:
return default_sql, default_params
case_joiner = case_joiner or self.case_joiner
Expand Down

0 comments on commit b2fec1f

Please sign in to comment.