Skip to content

Commit

Permalink
fix cache bug
Browse files Browse the repository at this point in the history
  • Loading branch information
depocoder committed Nov 13, 2024
1 parent 78d31fb commit 9b18599
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions backend/yet_another_calendar/web/api/bulk/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ async def refresh_events(
timezone: str,
) -> schema.RefreshedCalendarResponse:
"""Clear events cache."""
cached_json = await get_cached_calendar(body, lms_user, jwt_token, calendar_id, cookies)
cached_json = await get_cached_calendar(body, lms_user, calendar_id, cookies)
cached_calendar = schema.CalendarResponse.model_validate(cached_json)
calendar = await get_calendar(body, lms_user, jwt_token, calendar_id, cookies)
changed = cached_calendar.get_hash() != calendar.get_hash()
try:
cache_key = default_key_builder(get_cached_calendar, args=(body, jwt_token, calendar_id, cookies), kwargs={})
cache_key = default_key_builder(get_cached_calendar, args=(body, calendar_id, cookies), kwargs={})
coder = FastAPICache.get_coder()
backend = FastAPICache.get_backend()
await backend.set(
Expand Down Expand Up @@ -127,8 +127,8 @@ async def get_calendar(
async def get_cached_calendar(
body: modeus_schema.ModeusEventsBody,
lms_user: lms_schema.User,
jwt_token: str,
calendar_id: int,
cookies: netology_schema.NetologyCookies,
) -> schema.CalendarResponse:
jwt_token = await modeus_schema.get_cookies_from_headers()
return await get_calendar(body, lms_user, jwt_token, calendar_id, cookies)
3 changes: 1 addition & 2 deletions backend/yet_another_calendar/web/api/bulk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ async def get_calendar(
body: modeus_schema.ModeusEventsBody,
lms_user: lms_schema.User,
cookies: Annotated[netology_schema.NetologyCookies, Depends(netology_schema.get_cookies_from_headers)],
jwt_token: Annotated[str, Depends(modeus_schema.get_cookies_from_headers)],
calendar_id: int = settings.netology_default_course_id,
time_zone: str = "Europe/Moscow",
) -> schema.CalendarResponse:
"""
Get events from Netology and Modeus, cached.
"""

cached_calendar = await integration.get_cached_calendar(body, lms_user, jwt_token, calendar_id, cookies)
cached_calendar = await integration.get_cached_calendar(body, lms_user, calendar_id, cookies)
if isinstance(cached_calendar, schema.CalendarResponse):
return cached_calendar.change_timezone(time_zone)
# else cached
Expand Down

0 comments on commit 9b18599

Please sign in to comment.