diff options
| author | Adam Johnson <me@adamj.eu> | 2020-04-22 19:28:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-22 20:28:01 +0200 |
| commit | 67f9d076cfc1858b94f9ed6d1a5ce2327dcc8d0d (patch) | |
| tree | 4e7c63bb29280eb611312eae391b199cd5f6b3fc | |
| parent | 060d9d4229c436c44cf8e3a301f34c4b1f9f6c85 (diff) | |
Avoided unnecessary recompilation of ordering clause regex in SQLCompiler.
| -rw-r--r-- | django/db/models/sql/compiler.py | 9 |
1 files 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): |
