fixing DQ issues
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
# middleware/rate_limiter.py
|
||||
"""Summary description ....
|
||||
|
||||
This module provides classes and functions for:
|
||||
- ....
|
||||
- ....
|
||||
- ....
|
||||
"""
|
||||
|
||||
import logging
|
||||
from collections import defaultdict, deque
|
||||
from datetime import datetime, timedelta
|
||||
@@ -8,7 +16,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RateLimiter:
|
||||
"""In-memory rate limiter using sliding window"""
|
||||
"""In-memory rate limiter using sliding window."""
|
||||
|
||||
def __init__(self):
|
||||
"""Class constructor."""
|
||||
@@ -21,7 +29,8 @@ class RateLimiter:
|
||||
self, client_id: str, max_requests: int, window_seconds: int
|
||||
) -> bool:
|
||||
"""
|
||||
Check if client is allowed to make a request
|
||||
Check if client is allowed to make a request.
|
||||
|
||||
Uses sliding window algorithm
|
||||
"""
|
||||
now = datetime.utcnow()
|
||||
@@ -50,7 +59,7 @@ class RateLimiter:
|
||||
return False
|
||||
|
||||
def _cleanup_old_entries(self):
|
||||
"""Clean up old entries to prevent memory leaks"""
|
||||
"""Clean up old entries to prevent memory leaks."""
|
||||
cutoff_time = datetime.utcnow() - timedelta(hours=24)
|
||||
|
||||
clients_to_remove = []
|
||||
@@ -72,7 +81,7 @@ class RateLimiter:
|
||||
)
|
||||
|
||||
def get_client_stats(self, client_id: str) -> Dict[str, int]:
|
||||
"""Get statistics for a specific client"""
|
||||
"""Get statistics for a specific client."""
|
||||
client_requests = self.clients.get(client_id, deque())
|
||||
|
||||
now = datetime.utcnow()
|
||||
|
||||
Reference in New Issue
Block a user