aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-05-30 14:38:50 +0100
committerNeil Alexander <neilalexander@users.noreply.github.com>2022-05-30 14:38:50 +0100
commitfb52b6cedcd35b43f799f99767c5c9e01876dd5e (patch)
treed32eb9d501cd5a89987d1cca737d1aadd8bf806f
parent9869dc2cbe8ae9e465c70f9a60f7b367773bed3d (diff)
Sort `resolve-state` output
-rw-r--r--cmd/resolve-state/main.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/cmd/resolve-state/main.go b/cmd/resolve-state/main.go
index 3a9f3ce4..26f25b9e 100644
--- a/cmd/resolve-state/main.go
+++ b/cmd/resolve-state/main.go
@@ -4,7 +4,9 @@ import (
"context"
"flag"
"fmt"
+ "sort"
"strconv"
+ "strings"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/roomserver/storage"
@@ -110,7 +112,8 @@ func main() {
}
fmt.Println("Resolving state")
- resolved, err := gomatrixserverlib.ResolveConflicts(
+ var resolved Events
+ resolved, err = gomatrixserverlib.ResolveConflicts(
gomatrixserverlib.RoomVersion(*roomVersion),
events,
authEvents,
@@ -120,6 +123,7 @@ func main() {
}
fmt.Println("Resolved state contains", len(resolved), "events")
+ sort.Sort(resolved)
filteringEventType := *filterType
count := 0
for _, event := range resolved {
@@ -135,3 +139,25 @@ func main() {
fmt.Println()
fmt.Println("Returned", count, "state events after filtering")
}
+
+type Events []*gomatrixserverlib.Event
+
+func (e Events) Len() int {
+ return len(e)
+}
+
+func (e Events) Swap(i, j int) {
+ e[i], e[j] = e[j], e[i]
+}
+
+func (e Events) Less(i, j int) bool {
+ typeDelta := strings.Compare(e[i].Type(), e[j].Type())
+ if typeDelta < 0 {
+ return true
+ }
+ if typeDelta > 0 {
+ return false
+ }
+ stateKeyDelta := strings.Compare(*e[i].StateKey(), *e[j].StateKey())
+ return stateKeyDelta < 0
+}