From 76096f5fb80cbc2ae2955dc52704c90e253f9a03 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 26 Mar 2024 13:10:15 +0530 Subject: [PATCH] perf: use meta for virtual and single checks (#25620) RQ workers spawn a new process for every job so site_cache does nothing to prevent repeated queries. --- frappe/model/utils/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/frappe/model/utils/__init__.py b/frappe/model/utils/__init__.py index 7d8a389ec9..1527ed6429 100644 --- a/frappe/model/utils/__init__.py +++ b/frappe/model/utils/__init__.py @@ -128,9 +128,11 @@ def get_fetch_values(doctype, fieldname, value): @site_cache() def is_virtual_doctype(doctype: str): - if frappe.db.has_column("DocType", "is_virtual"): - return frappe.db.get_value("DocType", doctype, "is_virtual") - return False + if frappe.flags.in_install or frappe.flags.in_migrate: + if frappe.db.has_column("DocType", "is_virtual"): + return frappe.db.get_value("DocType", doctype, "is_virtual") + else: + return getattr(frappe.get_meta(doctype), "is_virtual", False) @site_cache() @@ -140,4 +142,7 @@ def is_single_doctype(doctype: str) -> bool: if doctype in DOCTYPES_FOR_DOCTYPE: return False - return frappe.db.get_value("DocType", doctype, "issingle") + if frappe.flags.in_install or frappe.flags.in_migrate: + return frappe.db.get_value("DocType", doctype, "issingle") + else: + return getattr(frappe.get_meta(doctype), "issingle", False)