diff --git a/ocfweb/api/meeting_hours.py b/ocfweb/api/meeting_hours.py index ecaa2cdf..087ff861 100644 --- a/ocfweb/api/meeting_hours.py +++ b/ocfweb/api/meeting_hours.py @@ -1,40 +1,59 @@ +from typing import Any +from typing import List + from django.http import HttpRequest from django.http import JsonResponse -from ocflib.org.meeting_hours import read_current_meeting +from ocflib.org.meeting_hours import read_current_meetings from ocflib.org.meeting_hours import read_meeting_list -from ocflib.org.meeting_hours import read_next_meeting +from ocflib.org.meeting_hours import read_next_meetings + +from ocfweb.caching import periodic def get_meetings_list(request: HttpRequest) -> JsonResponse: return JsonResponse( - [item._asdict() for item in read_meeting_list()], + [item._asdict() for item in _read_meeting_list()], safe=False, ) -def get_next_meeting(request: HttpRequest) -> JsonResponse: - next_meeting = read_next_meeting() - if next_meeting is None: +def get_next_meetings(request: HttpRequest) -> JsonResponse: + next_meetings = _read_next_meetings() + if next_meetings is None: return JsonResponse( {}, status=204, ) return JsonResponse( - next_meeting._asdict(), + [next_meeting._asdict() for next_meeting in next_meetings], safe=False, ) -def get_current_meeting(request: HttpRequest) -> JsonResponse: - current_meeting = read_current_meeting() - if current_meeting is None: +def get_current_meetings(request: HttpRequest) -> JsonResponse: + current_meetings = _read_current_meetings() + if current_meetings is None: return JsonResponse( {}, status=204, ) return JsonResponse( - current_meeting._asdict(), + [current_meeting._asdict() for current_meeting in current_meetings], safe=False, ) + + +def _read_meeting_list() -> List[Any]: + return read_meeting_list() + + +@periodic(5) +def _read_next_meetings() -> List[Any]: + return read_next_meetings() + + +@periodic(5) +def _read_current_meetings() -> List[Any]: + return read_current_meetings() diff --git a/ocfweb/api/urls.py b/ocfweb/api/urls.py index 8b831736..6776e96c 100644 --- a/ocfweb/api/urls.py +++ b/ocfweb/api/urls.py @@ -17,8 +17,8 @@ path('lab/desktops', lab.desktop_usage, name='desktop_usage'), path('lab/num_users', stats.get_num_users_in_lab, name='get_num_users_in_lab'), path('lab/staff', stats.get_staff_in_lab, name='get_staff_in_lab'), - path('meetings/current', meeting_hours.get_current_meeting, name='current_meeting'), - path('meetings/next', meeting_hours.get_next_meeting, name='next_meeting'), + path('meetings/current', meeting_hours.get_current_meetings, name='current_meetings'), + path('meetings/next', meeting_hours.get_next_meetings, name='next_meetings'), path('meetings/list', meeting_hours.get_meetings_list, name='meetings_list'), path('lab/printers_summary', stats.get_printers_summary, name='get_printers_summary'), path('lab/desktop_usage', stats.get_desktop_usage, name='get_desktop_usage'),