From 9b1859965e6a69f21e712ec4e000bf0ef31d3ae6 Mon Sep 17 00:00:00 2001 From: Ivan Popov Date: Wed, 13 Nov 2024 15:08:02 +0300 Subject: [PATCH] fix cache bug --- backend/yet_another_calendar/web/api/bulk/integration.py | 6 +++--- backend/yet_another_calendar/web/api/bulk/views.py | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/yet_another_calendar/web/api/bulk/integration.py b/backend/yet_another_calendar/web/api/bulk/integration.py index d20c760..4bb5216 100644 --- a/backend/yet_another_calendar/web/api/bulk/integration.py +++ b/backend/yet_another_calendar/web/api/bulk/integration.py @@ -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( @@ -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) diff --git a/backend/yet_another_calendar/web/api/bulk/views.py b/backend/yet_another_calendar/web/api/bulk/views.py index bcf8e68..ed2268d 100644 --- a/backend/yet_another_calendar/web/api/bulk/views.py +++ b/backend/yet_another_calendar/web/api/bulk/views.py @@ -21,7 +21,6 @@ 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: @@ -29,7 +28,7 @@ async def get_calendar( 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