diff --git a/frappe/database/database.py b/frappe/database/database.py index b083ff1014..364f0c73cd 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 = {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..83c22090eb 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) @@ -137,16 +138,14 @@ class DBTable: if frappe.db.is_missing_column(e): # Unknown column 'column_name' in 'field list' continue - else: - raise + raise if max_length and max_length[0][0] and max_length[0][0] > new_length: if col.fieldname in self.columns: self.columns[col.fieldname].length = current_length - - frappe.msgprint(_("""Reverting length to {0} for '{1}' in '{2}'; - Setting the length as {3} will cause truncation of data.""") - .format(current_length, col.fieldname, self.doctype, new_length)) + info_message = _("Reverting length to {0} for '{1}' in '{2}'. Setting the length as {3} will cause truncation of data.") \ + .format(current_length, col.fieldname, self.doctype, new_length) + frappe.msgprint(info_message) def is_new(self): return self.table_name not in frappe.db.get_tables()