Skip to content
Snippets Groups Projects
Verified Commit e33a33eb authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Filter holidays more efficient

parent 618e3872
No related branches found
No related tags found
1 merge request!83Minimize query count
Pipeline #3646 passed
......@@ -720,11 +720,18 @@ class Holiday(ExtensibleModel):
@classmethod
def in_week(cls, week: CalendarWeek) -> Dict[int, Optional["Holiday"]]:
per_weekday = {}
holidays = Holiday.objects.in_week(week)
for weekday in range(TimePeriod.weekday_min, TimePeriod.weekday_max + 1):
holiday_date = week[weekday]
holidays = Holiday.objects.on_day(holiday_date)
if holidays.exists():
holidays = list(
filter(
lambda h: holiday_date >= h.date_start
and holiday_date <= h.date_end,
holidays,
)
)
if holidays:
per_weekday[weekday] = holidays[0]
return per_weekday
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment