Rename db accessor to be more descript

This commit is contained in:
Devon Hudson 2023-06-13 09:13:04 +01:00
parent b987917a19
commit ba08f41a27
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
3 changed files with 12 additions and 18 deletions

View file

@ -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:

View file

@ -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(

View file

@ -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) {