Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip useless delta updates – send full payload instead #388

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 14 additions & 17 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3038,24 +3038,21 @@ func (c *Client) makeRecoveredPubsDeltaFossil(recoveredPubs []*protocol.Publicat
if len(recoveredPubs) > 1 {
for i, pub := range recoveredPubs[1:] {
patch := fdelta.Create(prevPub.Data, pub.Data)
var deltaPub *protocol.Publication
delta := true
deltaData := patch
if len(patch) >= len(pub.Data) {
delta = false
deltaData = pub.Data
}
if c.transport.Protocol() == ProtocolTypeJSON {
// For JSON case we need to use JSON string (js) for patch.
deltaPub = &protocol.Publication{
Offset: pub.Offset,
Data: json.Escape(convert.BytesToString(patch)),
Info: pub.Info,
Tags: pub.Tags,
Delta: true,
}
} else {
deltaPub = &protocol.Publication{
Offset: pub.Offset,
Data: patch,
Info: pub.Info,
Tags: pub.Tags,
Delta: true,
}
deltaData = json.Escape(convert.BytesToString(deltaData))
}
deltaPub := &protocol.Publication{
Offset: pub.Offset,
Data: deltaData,
Info: pub.Info,
Tags: pub.Tags,
Delta: delta,
}
recoveredPubs[i+1] = deltaPub
prevPub = recoveredPubs[i]
Expand Down
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