Files
2026-06-06 19:32:24 +08:00

13 lines
324 B
Python

import time
_hits: dict[str, list[float]] = {}
def hit_too_often(key: str, limit: int, window_seconds: int) -> bool:
now = time.time()
start = now - window_seconds
recent = [value for value in _hits.get(key, []) if value >= start]
recent.append(now)
_hits[key] = recent
return len(recent) > limit