perf: Glob filesystem instead of DB reads etc

Why speak more word when less word do trick
This commit is contained in:
Gavin D'souza 2022-04-14 13:30:35 +05:30
parent 67478e25c3
commit c9fa6931ff

View file

@ -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):