mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-18 04:02:35 +03:00
feat: Add support for flexible throttling intervals
This commit introduces the ability to set custom time intervals for throttling, allowing users to specify intervals like per 5 minutes, per 2 hours, and per 5 days. This enhancement provides more flexibility in controlling request rates.
This commit is contained in:
parent
68dbb4890c
commit
35a63d8667
|
@ -102,10 +102,10 @@ class SimpleRateThrottle(BaseThrottle):
|
|||
"""
|
||||
if rate is None:
|
||||
return (None, None)
|
||||
|
||||
num, period = rate.split('/')
|
||||
quantity, unit = parse_quantity_and_unit(period).values()
|
||||
num_requests = int(num)
|
||||
|
||||
duration = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[unit[0]]
|
||||
total_duration = duration * int(quantity)
|
||||
return (num_requests, total_duration)
|
||||
|
|
Loading…
Reference in New Issue
Block a user