perf(go): skip empty realtime payload snapshots

This commit is contained in:
lingniu
2026-07-03 08:35:14 +08:00
parent 97362e3205
commit c1640b4332
2 changed files with 20 additions and 1 deletions

View File

@@ -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

View File

@@ -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
}