Skip to content

Commit

Permalink
send full state if diff does not reduce bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Jun 9, 2024
1 parent c5fffda commit 47f117d
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,22 +582,21 @@ func getDeltaPub(prevPub *Publication, fullPub *protocol.Publication, key prepar
deltaPub := fullPub
if prevPub != nil && key.DeltaType == DeltaTypeFossil {
patch := fdelta.Create(prevPub.Data, fullPub.Data)
delta := true
deltaData := patch
if len(patch) >= len(fullPub.Data) {
delta = false
deltaData = fullPub.Data
}
if key.ProtocolType == protocol.TypeJSON {
deltaPub = &protocol.Publication{
Offset: fullPub.Offset,
Data: json.Escape(convert.BytesToString(patch)),
Info: fullPub.Info,
Tags: fullPub.Tags,
Delta: true,
}
} else {
deltaPub = &protocol.Publication{
Offset: fullPub.Offset,
Data: patch,
Info: fullPub.Info,
Tags: fullPub.Tags,
Delta: true,
}
deltaData = json.Escape(convert.BytesToString(deltaData))
}
deltaPub = &protocol.Publication{
Offset: fullPub.Offset,
Data: deltaData,
Info: fullPub.Info,
Tags: fullPub.Tags,
Delta: delta,
}
} else if prevPub == nil && key.ProtocolType == protocol.TypeJSON && key.DeltaType == DeltaTypeFossil {
// In JSON and Fossil case we need to send full state in JSON string format.
Expand Down

0 comments on commit 47f117d

Please sign in to comment.