perf(slm): command center loads from cached status, no device pings

get_live_view fired two device calls on every command-center load:
/measurement-state (sends Measure?) and /live (fresh DOD read) — competing
with the monitor's DOD polling. Both are now redundant: the keepalive monitor
keeps NL43Status fresh (~1.3s) and the live-stream WS handles ongoing updates.

Read the cached /status once instead (no device call); derive is_measuring
from measurement_state. Command center opens instantly without poking the
device. (Relies on monitor_start_time now being in /status.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-09 22:57:45 +00:00
parent d92d01dc56
commit 170dedb138
+11 -18
View File
@@ -169,25 +169,18 @@ async def get_live_view(request: Request, unit_id: str, db: Session = Depends(ge
is_measuring = False is_measuring = False
try: try:
async with httpx.AsyncClient(timeout=10.0) as client: # Read SLMM's CACHED status (NL43Status) — no device call. The live monitor
# Get measurement state # keeps it fresh (~1.3s) and the live-stream WS provides ongoing updates, so we
state_response = await client.get( # no longer fire Measure? + a fresh DOD read at the device on every command-
f"{SLMM_BASE_URL}/api/nl43/{unit_id}/measurement-state" # center load (which competed with DOD polling for the single connection).
) async with httpx.AsyncClient(timeout=5.0) as client:
if state_response.status_code == 200: r = await client.get(f"{SLMM_BASE_URL}/api/nl43/{unit_id}/status")
state_data = state_response.json() if r.status_code == 200:
measurement_state = state_data.get("measurement_state", "Unknown") current_status = r.json().get("data", {})
is_measuring = state_data.get("is_measuring", False) measurement_state = current_status.get("measurement_state")
is_measuring = measurement_state in ("Start", "Measure")
# Get live status (measurement_start_time is already stored in SLMM database)
status_response = await client.get(
f"{SLMM_BASE_URL}/api/nl43/{unit_id}/live"
)
if status_response.status_code == 200:
status_data = status_response.json()
current_status = status_data.get("data", {})
except Exception as e: except Exception as e:
logger.error(f"Failed to get status for {unit_id}: {e}") logger.error(f"Failed to get cached status for {unit_id}: {e}")
return templates.TemplateResponse("partials/slm_live_view.html", { return templates.TemplateResponse("partials/slm_live_view.html", {
"request": request, "request": request,