From c1640b433281ec5767cd8823265fe5b702b48fd1 Mon Sep 17 00:00:00 2001 From: lingniu Date: Fri, 3 Jul 2026 08:35:14 +0800 Subject: [PATCH] perf(go): skip empty realtime payload snapshots --- .../internal/realtime/snapshot_writer.go | 2 +- .../internal/realtime/snapshot_writer_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/go/vehicle-gateway/internal/realtime/snapshot_writer.go b/go/vehicle-gateway/internal/realtime/snapshot_writer.go index 4d6e931d..50c1ee47 100644 --- a/go/vehicle-gateway/internal/realtime/snapshot_writer.go +++ b/go/vehicle-gateway/internal/realtime/snapshot_writer.go @@ -321,7 +321,7 @@ func hasRealtimePayload(env envelope.FrameEnvelope) bool { if len(env.Fields) > 0 { return true } - if _, ok := env.Parsed["data_units"]; ok { + if units, ok := env.Parsed["data_units"].([]any); ok && len(units) > 0 { return true } return false diff --git a/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go b/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go index ff6ee420..9059b9f5 100644 --- a/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go +++ b/go/vehicle-gateway/internal/realtime/snapshot_writer_test.go @@ -404,6 +404,25 @@ func TestSnapshotWriterSkipsGB32960HeartbeatWithoutRealtimePayload(t *testing.T) } } +func TestSnapshotWriterSkipsEmptyDataUnitsWithoutCoreFields(t *testing.T) { + exec := &recordingSnapshotExec{} + writer := NewSnapshotWriter(exec) + + if err := writer.Update(context.Background(), envelope.FrameEnvelope{ + Protocol: envelope.ProtocolGB32960, + MessageID: "0x02", + VIN: "VIN001", + EventTimeMS: 1782918600000, + ReceivedAtMS: 1782918601000, + Parsed: map[string]any{"data_units": []any{}}, + }); err != nil { + t.Fatalf("Update() error = %v", err) + } + if len(exec.calls) != 0 { + t.Fatalf("exec calls = %d, want 0", len(exec.calls)) + } +} + type recordingSnapshotExec struct { calls []snapshotExecCall }