summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2023-05-23 18:05:31 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-25 13:18:02 +0200
commitea8cbca579cc6742e119747fc1eb6ecf90638bce (patch)
treeb79d3204287a0400d3be4d7b17abc8106465df19 /django
parent9d756afb07de8ef6e4d1980413979496643f1c3b (diff)
Made MigrationRecorder cache has_table() result if django_migrations table exists.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/recorder.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
index 50876a9ee3..cf0bd4a2ce 100644
--- a/django/db/migrations/recorder.py
+++ b/django/db/migrations/recorder.py
@@ -47,6 +47,7 @@ class MigrationRecorder:
def __init__(self, connection):
self.connection = connection
+ self._has_table = False
@property
def migration_qs(self):
@@ -54,9 +55,16 @@ class MigrationRecorder:
def has_table(self):
"""Return True if the django_migrations table exists."""
+ # If the migrations table has already been confirmed to exist, don't
+ # recheck it's existence.
+ if self._has_table:
+ return True
+ # It hasn't been confirmed to exist, recheck.
with self.connection.cursor() as cursor:
tables = self.connection.introspection.table_names(cursor)
- return self.Migration._meta.db_table in tables
+
+ self._has_table = self.Migration._meta.db_table in tables
+ return self._has_table
def ensure_schema(self):
"""Ensure the table exists and has the correct schema."""