Optimized Case.as_sql() default compilation.

Moving compiler.compile(self.default) to the else clause avoids
the call when it's unneeded in the FullResultSet case.
This commit is contained in:
Tim Graham 2024-06-21 17:51:56 -04:00 committed by Sarah Boyce
parent 7264d7f750
commit b2fec1f08d
1 changed files with 2 additions and 1 deletions

View File

@ -1613,7 +1613,6 @@ class Case(SQLiteNumericMixin, Expression):
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)
@ -1624,6 +1623,8 @@ class Case(SQLiteNumericMixin, Expression):
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