Refs #27624 -- Optimized Query.clone() for non-combined queries.

This avoids constructing a generator expression and a new tuple if the
Query has no combined queries.
This commit is contained in:
Keryn Knight 2021-09-16 11:03:04 +01:00 committed by Mariusz Felisiak
parent b8f3a3ad54
commit 5353e7c250
1 changed files with 4 additions and 1 deletions

View File

@ -306,7 +306,10 @@ class Query(BaseExpression):
obj.annotations = self.annotations.copy()
if self.annotation_select_mask is not None:
obj.annotation_select_mask = self.annotation_select_mask.copy()
obj.combined_queries = tuple(query.clone() for query in self.combined_queries)
if self.combined_queries:
obj.combined_queries = tuple([
query.clone() for query in self.combined_queries
])
# _annotation_select_cache cannot be copied, as doing so breaks the
# (necessary) state in which both annotations and
# _annotation_select_cache point to the same underlying objects.