Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix meeting-hours caching #755

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions ocfweb/api/meeting_hours.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions ocfweb/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down