Why don't we support customized times for throttling out of the box? #9379
Answered
by
tomchristie
JVitorCarv
asked this question in
Ideas & Suggestions
-
https://github.com/encode/django-rest-framework/blob/master/rest_framework/throttling.py I am referring to the code in def parse_rate(self, rate):
"""
Given the request rate string, return a two tuple of:
[allowed number of requests], [period of time in seconds]
"""
if rate is None:
return (None, None)
time_keys = {"s": 1, "m": 60, "h": 3600, "d": 86400}
num, period = rate.split("/")
num_requests = int(num) if num else 1
duration_str = "".join(filter(str.isdigit, period))
duration_unit = period[-1]
if duration_str:
duration = int(duration_str) * time_keys[duration_unit]
else:
duration = time_keys[duration_unit]
return (num_requests, duration) |
Beta Was this translation helpful? Give feedback.
Answered by
tomchristie
Apr 11, 2024
Replies: 1 comment
-
Because having a simple constraint for the more typical case is an okay and reasonable design decision. (Yours is also an okay design decision, but it's not the one we've opted for.) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JVitorCarv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because having a simple constraint for the more typical case is an okay and reasonable design decision.
(Yours is also an okay design decision, but it's not the one we've opted for.)