mirror of
https://github.com/BigBodyCobain/Shadowbroker.git
synced 2026-08-13 22:20:37 +02:00
perf: UX-safe fetch trimming and instant layer-enable refresh.
Drop duplicate slow-tier weather/ukraine jobs, gate correlations when off, slim health probes, keyed layer-panel subscriptions, align backend layer defaults with the dashboard, and fetch CCTV/FIRMS/PSK/etc. synchronously on enable so toggles stay responsive without background prefetch waste.
This commit is contained in:
@@ -479,24 +479,27 @@ def update_slow_data():
|
||||
fetch_military_bases,
|
||||
fetch_scanners,
|
||||
fetch_psk_reporter,
|
||||
fetch_weather_alerts,
|
||||
# weather_alerts + ukraine_alerts: owned by dedicated scheduler jobs
|
||||
# (5 min and 2 min) — keep off slow tier to avoid duplicate upstream work.
|
||||
fetch_air_quality,
|
||||
fetch_fishing_activity,
|
||||
fetch_power_plants,
|
||||
fetch_ukraine_air_raid_alerts,
|
||||
fetch_malware_threats,
|
||||
fetch_cyber_threats,
|
||||
fetch_scm_suppliers,
|
||||
]
|
||||
_run_tasks("slow-tier", slow_funcs)
|
||||
# Run correlation engine after all data is fresh
|
||||
# Run correlation engine after all data is fresh (skip when overlay is off).
|
||||
try:
|
||||
from services.fetchers._store import is_any_active
|
||||
from services.correlation_engine import compute_correlations
|
||||
with _data_lock:
|
||||
snapshot = dict(latest_data)
|
||||
correlations = compute_correlations(snapshot)
|
||||
with _data_lock:
|
||||
latest_data["correlations"] = correlations
|
||||
|
||||
if is_any_active("correlations"):
|
||||
with _data_lock:
|
||||
snapshot = dict(latest_data)
|
||||
correlations = compute_correlations(snapshot)
|
||||
with _data_lock:
|
||||
latest_data["correlations"] = correlations
|
||||
except Exception as e:
|
||||
logger.error("Correlation engine failed: %s", e)
|
||||
try:
|
||||
|
||||
@@ -334,15 +334,15 @@ active_layers: dict[str, bool] = {
|
||||
"ships_passenger": True,
|
||||
"ships_tracked_yachts": True,
|
||||
"earthquakes": True,
|
||||
"cctv": True,
|
||||
"cctv": False,
|
||||
"ukraine_frontline": True,
|
||||
"global_incidents": True,
|
||||
"gps_jamming": True,
|
||||
"kiwisdr": True,
|
||||
"scanners": True,
|
||||
"firms": True,
|
||||
"firms": False,
|
||||
"internet_outages": True,
|
||||
"datacenters": True,
|
||||
"datacenters": False,
|
||||
"military_bases": True,
|
||||
"sigint_meshtastic": True,
|
||||
"sigint_aprs": True,
|
||||
@@ -353,9 +353,9 @@ active_layers: dict[str, bool] = {
|
||||
"satnogs": True,
|
||||
"tinygs": True,
|
||||
"ukraine_alerts": True,
|
||||
"power_plants": True,
|
||||
"power_plants": False,
|
||||
"viirs_nightlights": False,
|
||||
"psk_reporter": True,
|
||||
"psk_reporter": False,
|
||||
"correlations": True,
|
||||
"contradictions": True,
|
||||
"uap_sightings": True,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
"""Immediate data refresh when the operator enables a map layer.
|
||||
|
||||
Runs synchronously inside POST /api/layers so the frontend's post-toggle
|
||||
live-data refetch sees populated payloads (T_toggle_visible guardrail).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def snapshot_active_layers() -> dict[str, bool]:
|
||||
from services.fetchers._store import active_layers
|
||||
|
||||
return dict(active_layers)
|
||||
|
||||
|
||||
def refresh_newly_enabled_layers(before: dict[str, bool]) -> None:
|
||||
"""Fetch any layers that transitioned off → on."""
|
||||
from services.fetchers._store import active_layers, bump_data_version
|
||||
|
||||
refreshed = False
|
||||
|
||||
def _enabled(key: str) -> bool:
|
||||
return bool(active_layers.get(key, False))
|
||||
|
||||
def _was_off_now_on(key: str) -> bool:
|
||||
return not bool(before.get(key, False)) and _enabled(key)
|
||||
|
||||
if _was_off_now_on("cctv"):
|
||||
from services.fetchers.infrastructure import fetch_cctv
|
||||
|
||||
fetch_cctv()
|
||||
refreshed = True
|
||||
logger.info("CCTV loaded (layer enabled)")
|
||||
|
||||
if _was_off_now_on("firms"):
|
||||
from services.fetchers.earth_observation import (
|
||||
fetch_firms_country_fires,
|
||||
fetch_firms_fires,
|
||||
)
|
||||
|
||||
fetch_firms_fires()
|
||||
fetch_firms_country_fires()
|
||||
refreshed = True
|
||||
logger.info("FIRMS fires loaded (layer enabled)")
|
||||
|
||||
if _was_off_now_on("power_plants"):
|
||||
from services.fetchers.infrastructure import fetch_power_plants
|
||||
|
||||
fetch_power_plants()
|
||||
refreshed = True
|
||||
logger.info("Power plants loaded (layer enabled)")
|
||||
|
||||
if _was_off_now_on("psk_reporter"):
|
||||
from services.fetchers.infrastructure import fetch_psk_reporter
|
||||
|
||||
fetch_psk_reporter()
|
||||
refreshed = True
|
||||
logger.info("PSK Reporter loaded (layer enabled)")
|
||||
|
||||
if _was_off_now_on("datacenters"):
|
||||
from services.fetchers.infrastructure import fetch_datacenters
|
||||
|
||||
fetch_datacenters()
|
||||
refreshed = True
|
||||
logger.info("Datacenters loaded (layer enabled)")
|
||||
|
||||
if _was_off_now_on("fishing_activity"):
|
||||
from services.fetchers.geo import fetch_fishing_activity
|
||||
|
||||
fetch_fishing_activity()
|
||||
refreshed = True
|
||||
logger.info("Fishing activity loaded (layer enabled)")
|
||||
|
||||
if refreshed:
|
||||
bump_data_version()
|
||||
Reference in New Issue
Block a user