diff options
author | Keryn Knight <keryn@kerynknight.com> | 2021-09-16 11:03:04 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-20 12:34:18 +0200 |
commit | 5353e7c2505c0d0ab8232ad9c131b3c99c833988 (patch) | |
tree | a69b597cb7a253b8fa6a224c8e8283a9ab48a10e | |
parent | b8f3a3ad54b05b83774716483afac7d0b9535fb4 (diff) | |
download | django-5353e7c2505c0d0ab8232ad9c131b3c99c833988.tar.gz |
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.
-rw-r--r-- | django/db/models/sql/query.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 9427c05c21..388c60545f 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -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. |