Skip to content

Commit

Permalink
fix: Disable ratelimit when value is empty (#2178)
Browse files Browse the repository at this point in the history
* fix: Don't run ratelimit on empty key

* Disable on value null
  • Loading branch information
faucomte97 authored Sep 18, 2023
1 parent 9793686 commit ac08f00
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion portal/helpers/ratelimit.py
Original file line number Diff line number Diff line change
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 ac08f00

Please sign in to comment.