|
26 | 26 | _NETWORK_WINDOW_SECONDS = 60.0 |
27 | 27 | _network_samples: deque[tuple[float, int]] = deque() |
28 | 28 | _network_samples_lock = threading.Lock() |
| 29 | +_discovery_snapshot_cache: dict[ |
| 30 | + tuple[str, str], tuple[float, dict[str, dict[str, Any]]] |
| 31 | +] = {} |
| 32 | +_discovery_snapshot_cache_lock = threading.Lock() |
| 33 | +_DISCOVERY_SNAPSHOT_CACHE_SECONDS = 30.0 |
29 | 34 | DISCOVERY_PROBE_ACTIVE_SOURCES = 8 |
30 | 35 | DISCOVERY_MIN_SCAN_SOURCES = 12 |
31 | 36 | DISCOVERY_MIN_FINAL_RECORDS = 20 |
@@ -192,6 +197,28 @@ def discovery_strategy_snapshot( |
192 | 197 | return result |
193 | 198 |
|
194 | 199 |
|
| 200 | +def _cached_discovery_strategy_snapshot( |
| 201 | + connection: sqlite3.Connection, |
| 202 | + *, |
| 203 | + workspace: Path, |
| 204 | + catalog_path: Path | None, |
| 205 | +) -> dict[str, dict[str, Any]]: |
| 206 | + """Keep frequent dashboard polls from repeatedly aggregating history.""" |
| 207 | + key = (str(workspace), str(catalog_path or "")) |
| 208 | + now = time.monotonic() |
| 209 | + with _discovery_snapshot_cache_lock: |
| 210 | + cached = _discovery_snapshot_cache.get(key) |
| 211 | + if cached and cached[0] > now: |
| 212 | + return cached[1] |
| 213 | + result = discovery_strategy_snapshot(connection, catalog_path=catalog_path) |
| 214 | + with _discovery_snapshot_cache_lock: |
| 215 | + _discovery_snapshot_cache[key] = ( |
| 216 | + now + _DISCOVERY_SNAPSHOT_CACHE_SECONDS, |
| 217 | + result, |
| 218 | + ) |
| 219 | + return result |
| 220 | + |
| 221 | + |
195 | 222 | def connect_frontier(workspace: Path) -> sqlite3.Connection: |
196 | 223 | workspace.mkdir(parents=True, exist_ok=True) |
197 | 224 | connection = sqlite3.connect( |
@@ -927,8 +954,10 @@ def frontier_snapshot( |
927 | 954 | platform_metrics: dict[str, dict[str, Any]] = {} |
928 | 955 | platform_counts = frontier_platform_counts(connection) |
929 | 956 | circuits = provider_circuit_snapshot(connection, now=timestamp) |
930 | | - discovery_strategies = discovery_strategy_snapshot( |
931 | | - connection, catalog_path=catalog_path |
| 957 | + discovery_strategies = _cached_discovery_strategy_snapshot( |
| 958 | + connection, |
| 959 | + workspace=workspace, |
| 960 | + catalog_path=catalog_path, |
932 | 961 | ) |
933 | 962 | for platform in sorted(platform_counts): |
934 | 963 | downloads = [ |
|
0 commit comments