From 35a63d86670b7ccb86d8b87e382f966b5d109cb1 Mon Sep 17 00:00:00 2001 From: Pravin Kamble Date: Sun, 20 Aug 2023 23:40:05 +0530 Subject: [PATCH] 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. --- rest_framework/throttling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index 90c8cd918..3483b1713 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -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)