Merge handle_control_event and persist_event_if_needed
The split existed only so handle_control_event could log UnitStateChanged and then delegate; that's no longer worth its own function. Co-locating the UnitStateChanged special case with the other match arms makes its 'log-only, no persist' treatment self-evident, and the call chain drops from handle → persist → record to handle → record. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
52cd3e630e
commit
3b92c0028a
|
|
@ -105,28 +105,7 @@ async fn handle_control_event(
|
|||
ws_manager: Option<&Arc<WebSocketManager>>,
|
||||
metadata: &MetadataCache,
|
||||
) {
|
||||
// UnitStateChanged is high-frequency and intentionally not persisted;
|
||||
// it still needs tracing for local observability. All other events are
|
||||
// persisted via record_event, which emits tracing automatically.
|
||||
if let AppEvent::UnitStateChanged {
|
||||
unit_id,
|
||||
from_state,
|
||||
to_state,
|
||||
} = &event
|
||||
{
|
||||
tracing::info!("Unit {} state: {} -> {}", unit_id, from_state, to_state);
|
||||
}
|
||||
|
||||
persist_event_if_needed(&event, pool, ws_manager, metadata).await;
|
||||
}
|
||||
|
||||
async fn persist_event_if_needed(
|
||||
event: &AppEvent,
|
||||
pool: &sqlx::PgPool,
|
||||
ws_manager: Option<&Arc<WebSocketManager>>,
|
||||
metadata: &MetadataCache,
|
||||
) {
|
||||
let record: Option<EventInsert> = match event {
|
||||
let record: Option<EventInsert> = match &event {
|
||||
AppEvent::EquipmentStartCommandSent {
|
||||
equipment_id,
|
||||
unit_id,
|
||||
|
|
@ -280,11 +259,18 @@ async fn persist_event_if_needed(
|
|||
payload: serde_json::json!({ "unit_id": unit_id }),
|
||||
})
|
||||
}
|
||||
AppEvent::UnitStateChanged { .. } => None,
|
||||
// High-frequency, intentionally not persisted; tracing only for local observability.
|
||||
AppEvent::UnitStateChanged {
|
||||
unit_id,
|
||||
from_state,
|
||||
to_state,
|
||||
} => {
|
||||
tracing::info!("Unit {} state: {} -> {}", unit_id, from_state, to_state);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
let Some(record) = record else {
|
||||
return;
|
||||
};
|
||||
record_event(pool, ws_manager.map(Arc::as_ref), record).await;
|
||||
if let Some(record) = record {
|
||||
record_event(pool, ws_manager.map(Arc::as_ref), record).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue