From 638300efd066cc54b3428a2b3688579ca8eab201 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Tue, 7 Mar 2023 11:25:03 +0100 Subject: [PATCH] Sort the events and skip if eventID is equal beforeID --- cmd/backfill/main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/backfill/main.go b/cmd/backfill/main.go index a856557eb..22ba5d575 100644 --- a/cmd/backfill/main.go +++ b/cmd/backfill/main.go @@ -12,6 +12,7 @@ import ( "math/rand" "os" "regexp" + "sort" "time" "github.com/matrix-org/gomatrixserverlib" @@ -112,6 +113,7 @@ func main() { continue } var createSeen bool + sort.Sort(headeredEvents(evs)) for _, x := range evs { if _, ok := seenEvents[x.EventID()]; ok { continue @@ -147,6 +149,9 @@ func main() { if _, ok := seenEvents[x.EventID()]; ok { continue } + if x.EventID() == beforeEvID { + continue + } eventID = x.EventID() break } @@ -162,6 +167,20 @@ func main() { } } +type headeredEvents []*gomatrixserverlib.HeaderedEvent + +func (h headeredEvents) Len() int { + return len(h) +} + +func (h headeredEvents) Less(i, j int) bool { + return h[i].Depth() < h[j].Depth() +} + +func (h headeredEvents) Swap(i, j int) { + h[i], h[j] = h[j], h[i] +} + type backfiller struct { FedClient *gomatrixserverlib.FederationClient servers map[gomatrixserverlib.ServerName]struct{}