From 67f9d076cfc1858b94f9ed6d1a5ce2327dcc8d0d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 22 Apr 2020 19:28:01 +0100 Subject: [PATCH] Avoided unnecessary recompilation of ordering clause regex in SQLCompiler. --- django/db/models/sql/compiler.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 9433540d7c..05597173ee 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -16,9 +16,16 @@ from django.db.models.sql.query import Query, get_order_dir from django.db.transaction import TransactionManagementError from django.utils.functional import cached_property from django.utils.hashable import make_hashable +from django.utils.regex_helper import _lazy_re_compile class SQLCompiler: + # Multiline ordering SQL clause may appear from RawSQL. + ordering_parts = _lazy_re_compile( + r'^(.*)\s(?:ASC|DESC).*', + re.MULTILINE | re.DOTALL, + ) + def __init__(self, query, connection, using): self.query = query self.connection = connection @@ -31,8 +38,6 @@ class SQLCompiler: self.select = None self.annotation_col_map = None self.klass_info = None - # Multiline ordering SQL clause may appear from RawSQL. - self.ordering_parts = re.compile(r'^(.*)\s(ASC|DESC)(.*)', re.MULTILINE | re.DOTALL) self._meta_ordering = None def setup_query(self):