summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-11-17 19:55:27 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-11-18 15:41:25 +0100
commitd7a9f006ed6d6323d3d66e75354202f4d1174ea0 (patch)
tree2bec9db05387b6f2a8a5e4dcc1f66028ce89e581 /django/db/models/sql/query.py
parent15cb3c262a7df568bb5c0e3e07d5078c08ef59f4 (diff)
Refs #34717 -- Avoided computing aggregate refs twice.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index f50e012f82..2bc16b1df3 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -451,13 +451,14 @@ class Query(BaseExpression):
# Temporarily add aggregate to annotations to allow remaining
# members of `aggregates` to resolve against each others.
self.append_annotation_mask([alias])
+ aggregate_refs = aggregate.get_refs()
refs_subquery |= any(
getattr(self.annotations[ref], "contains_subquery", False)
- for ref in aggregate.get_refs()
+ for ref in aggregate_refs
)
refs_window |= any(
getattr(self.annotations[ref], "contains_over_clause", True)
- for ref in aggregate.get_refs()
+ for ref in aggregate_refs
)
aggregate = aggregate.replace_expressions(replacements)
self.annotations[alias] = aggregate