From fecd5688dc7a4f377b3474a21960f1a87eccf453 Mon Sep 17 00:00:00 2001 From: Russ Biggs Date: Fri, 13 Dec 2024 18:40:09 -0700 Subject: [PATCH] cache fix --- openaq_api/openaq_api/dependencies.py | 4 +++- openaq_api/openaq_api/v3/routers/auth.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/openaq_api/openaq_api/dependencies.py b/openaq_api/openaq_api/dependencies.py index 0cfc976..fe95a12 100644 --- a/openaq_api/openaq_api/dependencies.py +++ b/openaq_api/openaq_api/dependencies.py @@ -121,7 +121,9 @@ async def check_api_key( limited = True requests_used = int(value) ttl = await redis.ttl(key) - + request.state.rate_limiter = ( + f"{key}/{limit}/{requests_used}/{limit - requests_used}/{ttl}" + ) response.headers["x-ratelimit-limit"] = str(limit) response.headers["x-ratelimit-remaining"] = str(requests_used) response.headers["x-ratelimit-used"] = str(limit - requests_used) diff --git a/openaq_api/openaq_api/v3/routers/auth.py b/openaq_api/openaq_api/v3/routers/auth.py index 9e4e522..3abe3a0 100644 --- a/openaq_api/openaq_api/v3/routers/auth.py +++ b/openaq_api/openaq_api/v3/routers/auth.py @@ -243,7 +243,7 @@ async def get_register( if redis_client: async with redis_client.pipeline() as pipe: await pipe.sadd("keys", user_token).hset( - user_token, mapping={"rate": 2000} + user_token, mapping={"rate": 60} ).execute() return {"message": "success"} except Exception as e: