diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-09-05 14:17:04 +0100 |
---|---|---|
committer | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-09-05 14:17:04 +0100 |
commit | 1c1d09abd4009e3fcc76b71ad158fb16e5e776cc (patch) | |
tree | 83540878721204fdc11728b5763db4942cea76ee | |
parent | d1f87e63f1b744825f40e59b8202933608480a70 (diff) |
Optimise `resolve-state` tool
-rw-r--r-- | cmd/resolve-state/main.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/cmd/resolve-state/main.go b/cmd/resolve-state/main.go index 6852ab4f..f8bb130c 100644 --- a/cmd/resolve-state/main.go +++ b/cmd/resolve-state/main.go @@ -76,9 +76,14 @@ func main() { panic(err) } - var eventNIDs []types.EventNID + eventNIDMap := map[types.EventNID]struct{}{} for _, entry := range append(removed, added...) { - eventNIDs = append(eventNIDs, entry.EventNID) + eventNIDMap[entry.EventNID] = struct{}{} + } + + eventNIDs := make([]types.EventNID, 0, len(eventNIDMap)) + for eventNID := range eventNIDMap { + eventNIDs = append(eventNIDs, eventNID) } var eventEntries []types.Event @@ -129,12 +134,17 @@ func main() { stateEntries = append(stateEntries, entries...) } - var eventNIDs []types.EventNID + eventNIDMap := map[types.EventNID]struct{}{} for _, entry := range stateEntries { - eventNIDs = append(eventNIDs, entry.EventNID) + eventNIDMap[entry.EventNID] = struct{}{} + } + + eventNIDs := make([]types.EventNID, 0, len(eventNIDMap)) + for eventNID := range eventNIDMap { + eventNIDs = append(eventNIDs, eventNID) } - fmt.Println("Fetching", len(eventNIDs), "state events") + fmt.Println("Fetching", len(eventNIDMap), "state events") eventEntries, err := roomserverDB.Events(ctx, eventNIDs) if err != nil { panic(err) |