diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index de8f597c7..bba080a14 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -990,15 +990,12 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, roomID spec.Ro } func (r *Queryer) QuerySenderIDForUser(ctx context.Context, roomID string, userID spec.UserID) (spec.SenderID, error) { - roomInfo, err := r.DB.GetOrCreateRoomInfoFromID(ctx, roomID) + version, err := r.DB.GetRoomVersion(ctx, roomID) if err != nil { return "", err } - if roomInfo == nil { - return "", fmt.Errorf("No room info found for %s", roomID) - } - switch roomInfo.RoomVersion { + switch version { case gomatrixserverlib.RoomVersionPseudoIDs: return r.DB.GetSenderIDForUser(ctx, roomID, userID) default: diff --git a/roomserver/storage/interface.go b/roomserver/storage/interface.go index a29bf8cc8..e6efdea5b 100644 --- a/roomserver/storage/interface.go +++ b/roomserver/storage/interface.go @@ -189,7 +189,7 @@ type Database interface { ctx context.Context, userNID types.EventStateKeyNID, info *types.RoomInfo, eventIDs ...string, ) (map[string]*types.HeaderedEvent, error) GetOrCreateRoomInfo(ctx context.Context, event gomatrixserverlib.PDU) (*types.RoomInfo, error) - GetOrCreateRoomInfoFromID(ctx context.Context, roomID string) (*types.RoomInfo, error) + GetRoomVersion(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, error) GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error) GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error) MaybeRedactEvent( diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go index 265ea3c4c..d05c714f2 100644 --- a/roomserver/storage/shared/storage.go +++ b/roomserver/storage/shared/storage.go @@ -701,23 +701,20 @@ func (d *Database) GetOrCreateRoomInfo(ctx context.Context, event gomatrixserver }, err } -// GetOrCreateRoomInfo gets or creates a new RoomInfo, which is only safe to use with functions only needing a roomVersion or roomNID. -func (d *Database) GetOrCreateRoomInfoFromID(ctx context.Context, roomID string) (roomInfo *types.RoomInfo, err error) { - roomNID, nidOK := d.Cache.GetRoomServerRoomNID(roomID) +func (d *Database) GetRoomVersion(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, error) { cachedRoomVersion, versionOK := d.Cache.GetRoomVersion(roomID) - // if we found both, the roomNID and version in our cache, no need to query the database - if nidOK && versionOK { - return &types.RoomInfo{ - RoomNID: roomNID, - RoomVersion: cachedRoomVersion, - }, nil + if versionOK { + return cachedRoomVersion, nil } - roomInfo, err = d.RoomInfo(ctx, roomID) + roomInfo, err := d.RoomInfo(ctx, roomID) if err != nil { - return nil, err + return "", err } - return roomInfo, nil + if roomInfo == nil { + return "", fmt.Errorf("no room info available for %s", roomID) + } + return roomInfo.RoomVersion, nil } func (d *Database) GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error) {