From 0c03556ed75b5a59d7ca73464795aced0b1c0f77 Mon Sep 17 00:00:00 2001 From: Anas WS Date: Thu, 14 Mar 2024 17:01:30 +0530 Subject: [PATCH] linting fixed --- app/config/base.py | 4 +++- app/middlewares/cache_middleware.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/config/base.py b/app/config/base.py index 9536421..45b083d 100644 --- a/app/config/base.py +++ b/app/config/base.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pydantic import BaseSettings @@ -25,7 +27,7 @@ class Config: class Settings(BaseSettings): SECRET_KEY: str REDIS_URL: str - SENTRY_DSN: str + SENTRY_DSN: str | None SLACK_WEBHOOK_URL: str ALLOWED_HOSTS: list = ["*"] CACHE_MAX_AGE: int = 60 diff --git a/app/middlewares/cache_middleware.py b/app/middlewares/cache_middleware.py index 8698a50..0724cc5 100644 --- a/app/middlewares/cache_middleware.py +++ b/app/middlewares/cache_middleware.py @@ -41,12 +41,13 @@ async def dispatch(self, request: Request, call_next) -> Response: if request_type != "GET": return await call_next(request) - stored_cache = await retrieve_cache(key) + stored_cache, expire = await retrieve_cache(key) res = stored_cache and cache_control != "no-cache" if res: - headers = {"Cache-Control": f"max-age:{stored_cache[1]}"} - return StreamingResponse(iter([stored_cache[0]]), media_type="application/json", headers=headers) + headers = {"Cache-Control": f"max-age:{expire}"} + return StreamingResponse(iter([stored_cache]), media_type="application/json", headers=headers) + response: Response = await call_next(request) response_body = [chunk async for chunk in response.body_iterator] response.body_iterator = iterate_in_threadpool(iter(response_body))