Skip to content

Commit

Permalink
perf: improve get_holidays function
Browse files Browse the repository at this point in the history
(cherry picked from commit f31d431)
  • Loading branch information
krantheman authored and mergify[bot] committed Oct 14, 2024
1 parent 5777091 commit d2271e8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hrms/api/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ def insert_shift(

def get_holidays(month_start: str, month_end: str, employee_filters: dict[str, str]) -> dict[str, list[dict]]:
holidays = {}
holiday_lists = {}

for employee in frappe.get_list("Employee", filters=employee_filters, pluck="name"):
if holiday_list := get_holiday_list_for_employee(employee, raise_exception=False):
holidays[employee] = frappe.get_all(
if not (holiday_list := get_holiday_list_for_employee(employee, raise_exception=False)):
continue
if holiday_list not in holiday_lists:
holiday_lists[holiday_list] = frappe.get_all(
"Holiday",
filters={"parent": holiday_list, "holiday_date": ["between", [month_start, month_end]]},
fields=["name as holiday", "holiday_date", "description", "weekly_off"],
)
holidays[employee] = holiday_lists[holiday_list].copy()

return holidays

Expand Down

0 comments on commit d2271e8

Please sign in to comment.