Add AssignRoomNID to pre-assign roomNIDs (#3111)

This commit is contained in:
Till 2023-06-13 16:28:41 +02:00 committed by GitHub
parent 2c87972a3a
commit 7a2e325d10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View file

@ -662,6 +662,26 @@ func (d *Database) IsEventRejected(ctx context.Context, roomNID types.RoomNID, e
return d.EventsTable.SelectEventRejected(ctx, nil, roomNID, eventID)
}
func (d *Database) AssignRoomNID(ctx context.Context, roomID spec.RoomID, roomVersion gomatrixserverlib.RoomVersion) (roomNID types.RoomNID, err error) {
// This should already be checked, let's check it anyway.
_, err = gomatrixserverlib.GetRoomVersion(roomVersion)
if err != nil {
return 0, err
}
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
roomNID, err = d.assignRoomNID(ctx, txn, roomID.String(), roomVersion)
if err != nil {
return err
}
return nil
})
if err != nil {
return 0, err
}
// Not setting caches, as assignRoomNID already does this
return roomNID, 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) GetOrCreateRoomInfo(ctx context.Context, event gomatrixserverlib.PDU) (roomInfo *types.RoomInfo, err error) {
// Get the default room version. If the client doesn't supply a room_version