From c9fa6931ffc5dfbc9cd792904b7cba395cd03ca8 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 14 Apr 2022 13:30:35 +0530 Subject: [PATCH] perf: Glob filesystem instead of DB reads etc Why speak more word when less word do trick --- frappe/modules/utils.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/frappe/modules/utils.py b/frappe/modules/utils.py index 1f89dae716..b8ab6756a5 100644 --- a/frappe/modules/utils.py +++ b/frappe/modules/utils.py @@ -105,17 +105,12 @@ def sync_customizations(app: Optional[str] = None): apps = frappe.get_installed_apps() if not app else [app] for app_name in apps: - for module_name in frappe.local.app_modules.get(app_name) or []: - module_custom_folder = frappe.get_app_path(app_name, module_name, "custom") - if not os.path.exists(module_custom_folder): - continue + for json_file in glob(frappe.get_app_path(app_name, "**", "custom", "*.json")): + with open(json_file, "r") as f: + data = json.loads(f.read()) - for json_file in glob(os.path.join(module_custom_folder, "*.json")): - with open(os.path.join(module_custom_folder, json_file), "r") as f: - data = json.loads(f.read()) - - if data.get("sync_on_migrate"): - sync_customizations_for_doctype(data, module_custom_folder) + if data.get("sync_on_migrate"): + sync_customizations_for_doctype(data, os.path.dirname(json_file)) def sync_customizations_for_doctype(data: Dict, folder: str):