mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 11:41:38 +00:00
Sort resolve-state
output
This commit is contained in:
parent
9869dc2cbe
commit
fb52b6cedc
@ -4,7 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||||
@ -110,7 +112,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Resolving state")
|
fmt.Println("Resolving state")
|
||||||
resolved, err := gomatrixserverlib.ResolveConflicts(
|
var resolved Events
|
||||||
|
resolved, err = gomatrixserverlib.ResolveConflicts(
|
||||||
gomatrixserverlib.RoomVersion(*roomVersion),
|
gomatrixserverlib.RoomVersion(*roomVersion),
|
||||||
events,
|
events,
|
||||||
authEvents,
|
authEvents,
|
||||||
@ -120,6 +123,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Resolved state contains", len(resolved), "events")
|
fmt.Println("Resolved state contains", len(resolved), "events")
|
||||||
|
sort.Sort(resolved)
|
||||||
filteringEventType := *filterType
|
filteringEventType := *filterType
|
||||||
count := 0
|
count := 0
|
||||||
for _, event := range resolved {
|
for _, event := range resolved {
|
||||||
@ -135,3 +139,25 @@ func main() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Returned", count, "state events after filtering")
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user