Skip to content

Commit

Permalink
perf(cache): fix active SLA doctype caching (frappe#26861)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ankush committed Aug 9, 2021
1 parent ff22eae commit 7b53ca7
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

if sla_doctypes is None:
return set_documents_with_active_service_level_agreement()

return frappe.cache().hget("service_level_agreement", "active")
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):
Expand Down

0 comments on commit 7b53ca7

Please sign in to comment.