refactor(go): keep protocol realtime snapshots lightweight
This commit is contained in:
@@ -55,13 +55,16 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
return err
|
||||
}
|
||||
existingParsed, err := r.GetRealtimeRaw(ctx, vehicleKey, env.Protocol)
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
return err
|
||||
}
|
||||
if existingProtocol.VehicleKey != "" {
|
||||
protocolSnapshot = existingProtocol
|
||||
if protocolSnapshot.VIN == "" && vin != "" {
|
||||
protocolSnapshot.VIN = vin
|
||||
}
|
||||
mergeFields(&protocolSnapshot, env.Fields, eventMS)
|
||||
protocolSnapshot.Parsed = mergeParsedForProtocol(env.Protocol, protocolSnapshot.Parsed, env.Parsed)
|
||||
if eventMS >= protocolSnapshot.EventTimeMS {
|
||||
protocolSnapshot.EventTimeMS = eventMS
|
||||
protocolSnapshot.EventID = env.StableEventID()
|
||||
@@ -70,7 +73,8 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err
|
||||
}
|
||||
protocolSnapshot.UpdatedAtMS = nowMS
|
||||
}
|
||||
if err := r.setJSON(ctx, protocolKey(vehicleKey, env.Protocol), protocolSnapshot, r.cfg.ttl()); err != nil {
|
||||
protocolSnapshot.Parsed = mergeParsedForProtocol(env.Protocol, existingParsed, env.Parsed)
|
||||
if err := r.setJSON(ctx, protocolKey(vehicleKey, env.Protocol), protocolSnapshot.Lightweight(), r.cfg.ttl()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := r.setJSON(ctx, realtimeRawKey(vehicleKey, env.Protocol), protocolSnapshot.Parsed, r.cfg.ttl()); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user