dashboard: add keyboard shortcuts and optimize polling

- fetch.py: convert proxy validation cache to LRU with OrderedDict
  - thread-safe lock, move_to_end() on hits, evict oldest when full
- dashboard.js: add keyboard shortcuts (r=refresh, 1-9=tabs, t=theme, p=pause)
- dashboard.js: skip chart rendering for inactive tabs (reduces CPU)
This commit is contained in:
Username
2025-12-28 16:52:52 +01:00
parent 18ae73bfb8
commit e758ce7178
2 changed files with 88 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
import re, random, time, string
import json
import threading
from collections import OrderedDict
import rocksock
import network_stats
from http2 import RsHttp, _parse_url
@@ -9,9 +10,11 @@ from misc import _log, tor_proxy_url
config = None
# Cache for is_usable_proxy() - avoids repeated validation of same proxy strings
_proxy_valid_cache = {}
# LRU cache for is_usable_proxy() - avoids repeated validation of same proxy strings
# Uses OrderedDict to maintain insertion order; oldest entries evicted when full
_proxy_valid_cache = OrderedDict()
_proxy_valid_cache_max = 10000
_proxy_valid_cache_lock = threading.Lock()
class FetchSession(object):
@@ -603,16 +606,20 @@ def is_usable_proxy(proxy):
- Invalid port (0, >65535)
- Private/reserved ranges
Results are cached to avoid repeated validation of the same proxy strings.
Results are cached using LRU eviction to avoid repeated validation.
"""
# Check cache first
if proxy in _proxy_valid_cache:
return _proxy_valid_cache[proxy]
with _proxy_valid_cache_lock:
if proxy in _proxy_valid_cache:
# Move to end (most recently used)
_proxy_valid_cache.move_to_end(proxy)
return _proxy_valid_cache[proxy]
result = _validate_proxy(proxy)
# Cache result (with size limit)
if len(_proxy_valid_cache) < _proxy_valid_cache_max:
with _proxy_valid_cache_lock:
# Evict oldest entries if at capacity
while len(_proxy_valid_cache) >= _proxy_valid_cache_max:
_proxy_valid_cache.popitem(last=False)
_proxy_valid_cache[proxy] = result
return result