diff --git a/frappe/database/database.py b/frappe/database/database.py index b083ff1014..cc76745c2e 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -769,7 +769,16 @@ class Database(object): return ("tab" + doctype) in self.get_tables() def get_tables(self): - return [d[0] for d in self.sql("select table_name from information_schema.tables where table_schema not in ('pg_catalog', 'information_schema')")] + tables = frappe.cache().get_value('db_tables') + if not tables: + table_rows = self.sql(""" + SELECT table_name + FROM information_schema.tables + WHERE table_schema NOT IN ('pg_catalog', 'information_schema') + """) + tables = set([d[0] for d in table_rows]) + frappe.cache().set_value('db_tables', tables) + return tables def a_row_exists(self, doctype): """Returns True if atleast one row exists.""" diff --git a/frappe/database/schema.py b/frappe/database/schema.py index 28e055f382..3d484a1f1b 100644 --- a/frappe/database/schema.py +++ b/frappe/database/schema.py @@ -31,6 +31,7 @@ class DBTable: def sync(self): if self.is_new(): + frappe.cache().delete_key('db_tables') self.create() else: frappe.cache().hdel('table_columns', self.table_name)