From 61a9349789607f31cc657e7bbdc652f7b2a77b70 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 21 Aug 2022 16:14:09 +0530 Subject: [PATCH] perf: use is_virtual_doctype and remove limit This reduces 1 query for each child table read Removed limit cause with 1000+ doctypes in frappe+erpnext this cache will just keep getting trashed for no reason. There's clear upper bound on size so no need to limit it here. --- frappe/model/document.py | 7 ++----- frappe/model/utils/__init__.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/frappe/model/document.py b/frappe/model/document.py index 5add5fba4e..2a82b5af9a 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -15,6 +15,7 @@ from frappe.model import optional_fields, table_fields from frappe.model.base_document import BaseDocument, get_controller from frappe.model.docstatus import DocStatus from frappe.model.naming import set_new_name, validate_name +from frappe.model.utils import is_virtual_doctype from frappe.model.workflow import set_workflow_state_on_action, validate_workflow from frappe.utils import cstr, date_diff, file_lock, flt, get_datetime_str, now from frappe.utils.data import get_absolute_url @@ -154,11 +155,7 @@ class Document(BaseDocument): # Make sure not to query the DB for a child table, if it is a virtual one. # During frappe is installed, the property "is_virtual" is not available in tabDocType, so # we need to filter those cases for the access to frappe.db.get_value() as it would crash otherwise. - if ( - hasattr(self, "doctype") - and not hasattr(self, "module") - and frappe.db.get_value("DocType", df.options, "is_virtual", cache=True) - ): + if hasattr(self, "doctype") and not hasattr(self, "module") and is_virtual_doctype(df.options): self.set(df.fieldname, []) continue diff --git a/frappe/model/utils/__init__.py b/frappe/model/utils/__init__.py index 2220b3904f..bf6804ad05 100644 --- a/frappe/model/utils/__init__.py +++ b/frappe/model/utils/__init__.py @@ -128,6 +128,6 @@ def get_fetch_values(doctype, fieldname, value): return result -@site_cache(maxsize=128) +@site_cache() def is_virtual_doctype(doctype): return frappe.db.get_value("DocType", doctype, "is_virtual")