mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 12:52:24 +03:00
Add AssignRoomNID
to pre-assign roomNIDs (#3111)
This commit is contained in:
parent
2c87972a3a
commit
7a2e325d10
3 changed files with 44 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue