Skip to content

Commit

Permalink
Disable on value null
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 18, 2023
1 parent 5008fe4 commit 98ca001
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions portal/helpers/ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def is_ratelimited(request, group=None, fn=None, key=None, rate=None, method=ALL
the custom cache_key functionality.
"""
usage = get_usage(request, group, fn, key, rate, method, increment)
if usage is None or key == "" or key is None:
if usage is None:
return False

return usage["should_limit"]
Expand Down Expand Up @@ -161,7 +161,16 @@ def get_usage(request, group=None, fn=None, key=None, rate=None, method=ALL, inc

cache_name = getattr(settings, "RATELIMIT_USE_CACHE", "default")
cache = caches[cache_name]
cache_key = _make_cache_key(group, window, rate, value, method)

if value == "":
return {
"count": 0,
"limit": 0,
"should_limit": False,
"time_left": -1,
}
else:
cache_key = _make_cache_key(group, window, rate, value, method)

count = None
added = cache.add(cache_key, initial_value, period + EXPIRATION_FUDGE)
Expand Down

0 comments on commit 98ca001

Please sign in to comment.