From 8048c77526b2119e4b33f4368b6c4740fb08ef1f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 3 Aug 2022 12:45:24 +0100 Subject: [PATCH] More input tweaks --- roomserver/internal/input/input.go | 5 +++-- roomserver/internal/input/input_events.go | 4 ++-- .../internal/input/input_latest_events.go | 20 +++++++++---------- roomserver/storage/shared/storage.go | 7 ++++--- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go index ecd4ecbb5..a6f5585f9 100644 --- a/roomserver/internal/input/input.go +++ b/roomserver/internal/input/input.go @@ -60,8 +60,9 @@ import ( // per-room durable consumers will only progress through the stream // as events are processed. // -// A BC * -> positions of each consumer (* = ephemeral) -// ⌄ ⌄⌄ ⌄ +// A BC * -> positions of each consumer (* = ephemeral) +// ⌄ ⌄⌄ ⌄ +// // ABAABCAABCAA -> newest (letter = subject for each message) // // In this example, A is still processing an event but has two diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go index 797341dcd..92a6075fe 100644 --- a/roomserver/internal/input/input_events.go +++ b/roomserver/internal/input/input_events.go @@ -137,7 +137,7 @@ func (r *Inputer) processRoomEvent( return fmt.Errorf("r.DB.RoomInfo: %w", rerr) } isCreateEvent := event.Type() == gomatrixserverlib.MRoomCreate && event.StateKeyEquals("") - if roomInfo == nil && !isCreateEvent { + if !isCreateEvent && (roomInfo == nil || roomInfo.IsStub()) { return fmt.Errorf("room %s does not exist for event %s", event.RoomID(), event.EventID()) } @@ -341,7 +341,7 @@ func (r *Inputer) processRoomEvent( if err != nil { return fmt.Errorf("updater.RoomInfo: %w", err) } - if roomInfo == nil { + if roomInfo == nil || (!isCreateEvent && roomInfo.IsStub()) { return fmt.Errorf("updater.RoomInfo missing for room %s", event.RoomID()) } diff --git a/roomserver/internal/input/input_latest_events.go b/roomserver/internal/input/input_latest_events.go index f7d15fdb5..e3a573ed6 100644 --- a/roomserver/internal/input/input_latest_events.go +++ b/roomserver/internal/input/input_latest_events.go @@ -35,17 +35,17 @@ import ( // event to the output log. // The latest events are the events that aren't referenced by another event in the database: // -// Time goes down the page. 1 is the m.room.create event (root). +// Time goes down the page. 1 is the m.room.create event (root). // -// 1 After storing 1 the latest events are {1} -// | After storing 2 the latest events are {2} -// 2 After storing 3 the latest events are {3} -// / \ After storing 4 the latest events are {3,4} -// 3 4 After storing 5 the latest events are {5,4} -// | | After storing 6 the latest events are {5,6} -// 5 6 <--- latest After storing 7 the latest events are {6,7} -// | -// 7 <----- latest +// 1 After storing 1 the latest events are {1} +// | After storing 2 the latest events are {2} +// 2 After storing 3 the latest events are {3} +// / \ After storing 4 the latest events are {3,4} +// 3 4 After storing 5 the latest events are {5,4} +// | | After storing 6 the latest events are {5,6} +// 5 6 <--- latest After storing 7 the latest events are {6,7} +// | +// 7 <----- latest // // Can only be called once at a time func (r *Inputer) updateLatestEvents( diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go index 306805a53..afb6c3494 100644 --- a/roomserver/storage/shared/storage.go +++ b/roomserver/storage/shared/storage.go @@ -178,7 +178,7 @@ func (d *Database) roomInfo(ctx context.Context, txn *sql.Tx, roomID string) (*t } // Otherwise, try to admit the data into the cache and return the // new reference from the database. - if roomInfoFromDB != nil { + if err == nil && roomInfoFromDB != nil { d.Cache.StoreRoomInfo(roomID, roomInfoFromDB) d.Cache.StoreRoomServerRoomID(roomInfoFromDB.RoomNID, roomID) } @@ -840,8 +840,9 @@ func extractRoomVersionFromCreateEvent(event *gomatrixserverlib.Event) ( // "servers should not apply or send redactions to clients until both the redaction event and original event have been seen, and are valid." // https://matrix.org/docs/spec/rooms/v3#authorization-rules-for-events // These cases are: -// - This is a redaction event, redact the event it references if we know about it. -// - This is a normal event which may have been previously redacted. +// - This is a redaction event, redact the event it references if we know about it. +// - This is a normal event which may have been previously redacted. +// // In the first case, check if we have the referenced event then apply the redaction, else store it // in the redactions table with validated=FALSE. In the second case, check if there is a redaction for it: // if there is then apply the redactions and set validated=TRUE.