fix:批量修复了一些问题

This commit is contained in:
shangfangjian
2026-09-19 22:51:35 +08:00
parent 835d7217d0
commit 8e6ad5394e
44 changed files with 4921 additions and 395 deletions
+6
View File
@@ -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)