fix: autoincr caching and clear site cache after restore (#22079)
* fix: remove hazardous cache for autoincr * fix: move cache to redis * fix: clear all redis cache after restoring a site
This commit is contained in:
parent
4649c8dacf
commit
79392260d4
2 changed files with 14 additions and 15 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue