Skip to content

Commit

Permalink
perf: cache and simplify queries for holiday list (#35315)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9feda1b)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed May 16, 2023
1 parent 19f08af commit 96332db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion erpnext/setup/doctype/employee/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ def get_employee_email(employee_doc):

def get_holiday_list_for_employee(employee, raise_exception=True):
if employee:
holiday_list, company = frappe.db.get_value("Employee", employee, ["holiday_list", "company"])
holiday_list, company = frappe.get_cached_value(
"Employee", employee, ["holiday_list", "company"]
)
else:
holiday_list = ""
company = frappe.db.get_single_value("Global Defaults", "default_company")
Expand Down
4 changes: 3 additions & 1 deletion erpnext/setup/doctype/holiday_list/holiday_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def is_holiday(holiday_list, date=None):
if date is None:
date = today()
if holiday_list:
return bool(frappe.get_all("Holiday List", dict(name=holiday_list, holiday_date=date)))
return bool(
frappe.db.exists("Holiday", {"parent": holiday_list, "holiday_date": date}, cache=True)
)
else:
return False

0 comments on commit 96332db

Please sign in to comment.