fetch: cache is_usable_proxy results
All checks were successful
CI / syntax-check (push) Successful in 3s
CI / memory-leak-check (push) Successful in 11s

This commit is contained in:
Username
2025-12-26 20:04:01 +01:00
parent 1f41f3df5c
commit 906d1b33ae

View File

@@ -9,6 +9,10 @@ from misc import _log
config = None
# Cache for is_usable_proxy() - avoids repeated validation of same proxy strings
_proxy_valid_cache = {}
_proxy_valid_cache_max = 10000
def tor_proxy_url(torhost):
"""Generate Tor SOCKS5 proxy URL with random credentials for circuit isolation."""
@@ -616,7 +620,24 @@ def is_usable_proxy(proxy):
- Malformed strings
- Invalid port (0, >65535)
- Private/reserved ranges
Results are cached to avoid repeated validation of the same proxy strings.
"""
# Check cache first
if proxy in _proxy_valid_cache:
return _proxy_valid_cache[proxy]
result = _validate_proxy(proxy)
# Cache result (with size limit)
if len(_proxy_valid_cache) < _proxy_valid_cache_max:
_proxy_valid_cache[proxy] = result
return result
def _validate_proxy(proxy):
"""Internal validation logic for is_usable_proxy."""
try:
if ':' not in proxy:
return False