优化网络与系统检测为缓存优先,避免页面长时间停留在检测中。

将网络/IP 路由拆分并加入去重缓存,系统检测改为线程执行并支持强制刷新,前端改为先展示缓存快照后按需手动重测,降低阻塞与重复探测开销。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric
2026-07-08 14:38:59 -05:00
parent 1287b72193
commit 0661c33610
7 changed files with 375 additions and 126 deletions

View File

@@ -4,6 +4,8 @@ from __future__ import annotations
import platform
import socket
import subprocess
import threading
import time
from typing import Any
@@ -20,8 +22,10 @@ def detect_nvidia_gpu() -> bool:
return False
def detect_nvenc_available() -> bool:
if not detect_nvidia_gpu():
def detect_nvenc_available(nvidia_present: bool | None = None) -> bool:
if nvidia_present is None:
nvidia_present = detect_nvidia_gpu()
if not nvidia_present:
return False
try:
_kw = {"capture_output": True, "text": True, "timeout": 8}
@@ -33,13 +37,27 @@ def detect_nvenc_available() -> bool:
return False
def gpu_status_payload() -> dict[str, Any]:
_GPU_STATUS_CACHE_TTL_SECONDS = 60.0
_gpu_status_lock = threading.Lock()
_gpu_status_cache: tuple[float, dict[str, Any]] | None = None
def gpu_status_payload(force_refresh: bool = False) -> dict[str, Any]:
global _gpu_status_cache
now = time.time()
with _gpu_status_lock:
if not force_refresh and _gpu_status_cache and (now - _gpu_status_cache[0]) < _GPU_STATUS_CACHE_TTL_SECONDS:
return dict(_gpu_status_cache[1])
nv = detect_nvidia_gpu()
enc = detect_nvenc_available()
return {
enc = detect_nvenc_available(nv)
payload = {
"nvidia_detected": nv,
"nvenc_available": enc,
}
with _gpu_status_lock:
_gpu_status_cache = (time.time(), payload)
return dict(payload)
def machine_summary_payload() -> dict[str, Any]: