perf(cache): fix active SLA doctype caching (#26861)

If no SLA is configured then this query runs on EVERY `validate` call.

Root cause: if not active SLA doctypes exist then `not []` evalutes to
true and causes query to run again.
This commit is contained in:
Ankush 2021-08-09 22:15:49 +05:30 committed by GitHub
parent b92c404ed0
commit 5e428f0447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -281,15 +281,18 @@ def get_repeated(values):
def get_documents_with_active_service_level_agreement():
if not frappe.cache().hget("service_level_agreement", "active"):
set_documents_with_active_service_level_agreement()
sla_doctypes = frappe.cache().hget("service_level_agreement", "active")
return frappe.cache().hget("service_level_agreement", "active")
if sla_doctypes is None:
return set_documents_with_active_service_level_agreement()
return sla_doctypes
def set_documents_with_active_service_level_agreement():
active = [sla.document_type for sla in frappe.get_all("Service Level Agreement", fields=["document_type"])]
frappe.cache().hset("service_level_agreement", "active", active)
return active
def apply(doc, method=None):