diff --git a/frappe/database/db_manager.py b/frappe/database/db_manager.py index a1761b5995..bd696d00e3 100644 --- a/frappe/database/db_manager.py +++ b/frappe/database/db_manager.py @@ -78,4 +78,6 @@ class DbManager: source=source, port=frappe.conf.db_port, ) + os.system(command) + frappe.cache.delete_keys("") # Delete all keys associated with this site. diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 267b89d6ae..c90b7f517b 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -12,17 +12,13 @@ from frappe import _ from frappe.model import log_types from frappe.query_builder import DocType from frappe.utils import cint, cstr, now_datetime +from frappe.utils.caching import redis_cache if TYPE_CHECKING: from frappe.model.document import Document from frappe.model.meta import Meta -# NOTE: This is used to keep track of status of sites -# whether `log_types` have autoincremented naming set for the site or not. -# Structure: {"sitename": {"doctype": 1}} -autoincremented_site_status_map = defaultdict(dict) - NAMING_SERIES_PATTERN = re.compile(r"^[\w\- \/.#{}]+$", re.UNICODE) BRACED_PARAMS_PATTERN = re.compile(r"(\{[\w | #]+\})") @@ -182,16 +178,7 @@ def is_autoincremented(doctype: str, meta: Optional["Meta"] = None) -> bool: """Checks if the doctype has autoincrement autoname set""" if doctype in log_types: - site_map = autoincremented_site_status_map[frappe.local.site] - if site_map.get(doctype) is None: - query = f"""select data_type FROM information_schema.columns where column_name = 'name' and table_name = 'tab{doctype}'""" - values = () - if frappe.db.db_type == "mariadb": - query += " and table_schema = %s" - values = (frappe.db.db_name,) - site_map[doctype] = frappe.db.sql(query, values)[0][0] == "bigint" - - return bool(site_map[doctype]) + return _implicitly_auto_incremented(doctype) else: if not meta: meta = frappe.get_meta(doctype) @@ -202,6 +189,16 @@ def is_autoincremented(doctype: str, meta: Optional["Meta"] = None) -> bool: return False +@redis_cache +def _implicitly_auto_incremented(doctype) -> bool: + query = f"""select data_type FROM information_schema.columns where column_name = 'name' and table_name = 'tab{doctype}'""" + values = () + if frappe.db.db_type == "mariadb": + query += " and table_schema = %s" + values = (frappe.db.db_name,) + return frappe.db.sql(query, values)[0][0] == "bigint" + + def set_name_from_naming_options(autoname, doc): """ Get a name based on the autoname field option