fix:批量修复了一些问题
This commit is contained in:
@@ -167,6 +167,12 @@ class _RateLimiter:
|
||||
self._hits[key] = timestamps
|
||||
return True
|
||||
|
||||
def remaining(self, key: str) -> int:
|
||||
"""当前窗口内剩余可用次数。"""
|
||||
now = time.time()
|
||||
timestamps = [t for t in self._hits.get(key, []) if t > now - self.window_seconds]
|
||||
return max(0, self.max_requests - len(timestamps))
|
||||
|
||||
|
||||
# 全局限流实例: /api/v1/predict 每分钟 10 次
|
||||
_predict_limiter = _RateLimiter(max_requests=10, window_seconds=60)
|
||||
|
||||
Reference in New Issue
Block a user