perf(go): skip empty realtime payload snapshots
This commit is contained in:
@@ -321,7 +321,7 @@ func hasRealtimePayload(env envelope.FrameEnvelope) bool {
|
|||||||
if len(env.Fields) > 0 {
|
if len(env.Fields) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if _, ok := env.Parsed["data_units"]; ok {
|
if units, ok := env.Parsed["data_units"].([]any); ok && len(units) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -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 {
|
type recordingSnapshotExec struct {
|
||||||
calls []snapshotExecCall
|
calls []snapshotExecCall
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user