Skip to content

Commit

Permalink
jsonpatcher: sort events by ts in the reducer (#334)
Browse files Browse the repository at this point in the history
Signed-off-by: requilence <[email protected]>
  • Loading branch information
requilence authored May 7, 2020
1 parent e73e2b1 commit d4f1723
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions jsonpatcher/jsonpatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"sort"
"time"

jsonpatch "github.com/evanphx/json-patch"
Expand Down Expand Up @@ -104,6 +105,17 @@ func (jp *jsonPatcher) Reduce(
}
defer txn.Discard()

sort.Slice(events, func(i, j int) bool {
ei, oki := events[i].(patchEvent)
ej, okj := events[j].(patchEvent)

if !(oki && okj) {
return false
}

return ei.Timestamp.Before(ej.Timestamp)
})

actions := make([]core.ReduceAction, len(events))
for i, e := range events {
je, ok := e.(patchEvent)
Expand Down

0 comments on commit d4f1723

Please sign in to comment.