Add a clear cache method to the Database

ExtensionTestCase uses this new method to clear all the caches of the Database.
This commit is contained in:
Nicolas Évrard committed 2025-10-28 10:57:07 +01:00
1 parent 3850af11f7
commit f70d515905
6 files changed
+29 -8

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Add a clear cache method to the Database
* Add sequence_reorder to model order
* Remove has_window_functions from Database
* Set minimal supported version of SQLite to 3.30.0
+4
View File
@@ -50,6 +50,10 @@ Database
Drop the named database using the connection.
.. classmethod:: Database.clear_cache()
Clear the cached values regarding the database properties.
.. method:: Database.list([hostname])
Return a list of Tryton database names.
+4
View File
@@ -45,6 +45,10 @@ class DatabaseInterface(object):
def drop(cls, connection, database_name):
raise NotImplementedError
@classmethod
def clear_cache(cls):
pass
def list(self, hostname=None):
raise NotImplementedError
+13 -2
View File
@@ -330,9 +330,20 @@ class Database(DatabaseInterface):
cursor = connection.cursor()
cursor.execute(SQL("DROP DATABASE {}")
.format(Identifier(database_name)))
cls.clear_cache()
@classmethod
def clear_cache(cls):
cls._list_cache.clear()
cls._has_proc.pop(database_name, None)
cls._search_full_text_languages.pop(database_name, None)
cls._list_cache_timestamp.clear()
cls._search_path = None
cls._current_user = None
cls._has_returning = None
cls._has_insert_on_conflict = None
cls._has_select_for_skip_locked = None
cls._has_proc.clear()
cls._extensions.clear()
cls._search_full_text_languages.clear()
def get_version(self, connection):
version = connection.server_version
@@ -613,7 +613,12 @@ class Database(DatabaseInterface):
os.remove(file + suffix)
except FileNotFoundError:
pass
cls.clear_cache()
@classmethod
def clear_cache(cls):
cls._list_cache.clear()
cls._list_cache_timestamp.clear()
def list(self, hostname=None):
now = time.time()
+2 -6
View File
@@ -1265,7 +1265,7 @@ class ExtensionTestCase(TestCase):
cursor = connection.cursor()
cursor.execute('CREATE EXTENSION "%s"' % cls.extension)
connection.commit()
cls._clear_cache()
backend.Database.clear_cache()
@classmethod
@with_transaction()
@@ -1274,11 +1274,7 @@ class ExtensionTestCase(TestCase):
cursor = connection.cursor()
cursor.execute('DROP EXTENSION "%s"' % cls.extension)
connection.commit()
cls._clear_cache()
@classmethod
def _clear_cache(cls):
backend.Database._has_proc.clear()
backend.Database.clear_cache()
def drop_db(name=DB_NAME):