diff --git a/dank_mids/helpers/_session.py b/dank_mids/helpers/_session.py index e8461008..d3c12b4f 100644 --- a/dank_mids/helpers/_session.py +++ b/dank_mids/helpers/_session.py @@ -226,7 +226,7 @@ async def post(self, endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DEC async def handle_too_many_requests(self, endpoint: str, error: ClientResponseError) -> None: limiter = limiters[endpoint] - if (now := time()) > getattr(limiter, "_last_updated_at", 0) + 30: + if (now := time()) > getattr(limiter, "_last_updated_at", 0) + 10: current_rate = limiter._rate_per_sec new_rate = current_rate * 0.97 limiter._rate_per_sec = new_rate @@ -252,7 +252,8 @@ async def handle_too_many_requests(self, endpoint: str, error: ClientResponseErr self._log_rate_limited(retry_after) if retry_after > 30: _logger_warning("severe rate limiting from your provider") - await sleep(retry_after) + acquire_capacity_for_x_requests = retry_after / secs_between_requests + await limiter.acquire(acquire_capacity_for_x_requests) def _log_rate_limited(self, try_after: float) -> None: if not self._limited: