mirror of https://github.com/zulip/zulip.git
rate_limiter: Fix too early return if no rules are passed in.
In the redis implementation, if rules was an empty list, this would return too early - before checking if the key isn't manually blocked.
This commit is contained in:
parent
cb85763c78
commit
95fa8b2a26
|
@ -222,9 +222,6 @@ class RedisRateLimiterBackend(RateLimiterBackend):
|
||||||
"Returns a tuple of (rate_limited, time_till_free)"
|
"Returns a tuple of (rate_limited, time_till_free)"
|
||||||
list_key, set_key, blocking_key = cls.get_keys(entity_key)
|
list_key, set_key, blocking_key = cls.get_keys(entity_key)
|
||||||
|
|
||||||
if len(rules) == 0:
|
|
||||||
return False, 0.0
|
|
||||||
|
|
||||||
# Go through the rules from shortest to longest,
|
# Go through the rules from shortest to longest,
|
||||||
# seeing if this user has violated any of them. First
|
# seeing if this user has violated any of them. First
|
||||||
# get the timestamps for each nth items
|
# get the timestamps for each nth items
|
||||||
|
@ -250,6 +247,9 @@ class RedisRateLimiterBackend(RateLimiterBackend):
|
||||||
blocking_ttl = int(blocking_ttl_b)
|
blocking_ttl = int(blocking_ttl_b)
|
||||||
return True, blocking_ttl
|
return True, blocking_ttl
|
||||||
|
|
||||||
|
if len(rules) == 0:
|
||||||
|
return False, 0.0
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
for timestamp, (range_seconds, num_requests) in zip(rule_timestamps, rules):
|
for timestamp, (range_seconds, num_requests) in zip(rule_timestamps, rules):
|
||||||
# Check if the nth timestamp is newer than the associated rule. If so,
|
# Check if the nth timestamp is newer than the associated rule. If so,
|
||||||
|
|
Loading…
Reference in New Issue