From 7928138034c31bc8d4f2094969828a240b3177a6 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 13 Sep 2022 11:10:57 +0100 Subject: [PATCH] Exclude events we don't know state for --- roomserver/internal/query/query.go | 6 +++++- roomserver/state/state.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index d08c5c491..a34ac35e7 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -237,7 +237,11 @@ func (r *Queryer) QueryMembershipAtEvent( } for _, eventID := range request.EventIDs { - stateEntry := stateEntries[eventID] + stateEntry, ok := stateEntries[eventID] + if !ok { + response.Memberships[eventID] = []*gomatrixserverlib.HeaderedEvent{} + continue + } memberships, err := helpers.GetMembershipsAtState(ctx, r.DB, stateEntry, false) if err != nil { return fmt.Errorf("unable to get memberships at state: %w", err) diff --git a/roomserver/state/state.go b/roomserver/state/state.go index f53d657b7..cb96d83ec 100644 --- a/roomserver/state/state.go +++ b/roomserver/state/state.go @@ -139,6 +139,9 @@ func (v *StateResolution) LoadMembershipAtEvent( return nil, fmt.Errorf("LoadStateAtEvent.SnapshotNIDFromEventID failed for event %s : %w", eventID, err) } if snapshotNID == 0 { + // If we don't know a state snapshot for this event then we can't calculate + // memberships at the time of the event, so skip over it. This means that + // it isn't guaranteed that the response map will contain every single event. continue } snapshotNIDMap[snapshotNID] = append(snapshotNIDMap[snapshotNID], eventID)