Skip to content

Commit

Permalink
revert to old key method
Browse files Browse the repository at this point in the history
  • Loading branch information
russbiggs committed Dec 13, 2024
1 parent 254a0fd commit b85a49a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions openaq_api/openaq_api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ async def check_api_key(
limit = 60
limited = False
# check if its limited
key = f"{api_key}"
now = datetime.now()
# Using a sliding window rate limiting algorithm
# we add the current time to the minute to the api key and use that as our check
key = f"{api_key}:{now.year}{now.month}{now.day}{now.hour}{now.minute}"
# if the that key is in our redis db it will return the number of requests
# that key has made during the current minute
value = await redis.get(key)
Expand Down Expand Up @@ -118,9 +121,6 @@ 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)
Expand Down

0 comments on commit b85a49a

Please sign in to comment.