mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Update room version descriptors, add error handling (#906)
* Update room version descriptors, add error handling * Fix database queries * Drop Get from version package * Fix database wrapping, add comments for version descriptions * Don't set default room_version value in SQL
This commit is contained in:
parent
dfd8b93d93
commit
452f393dd7
9 changed files with 121 additions and 95 deletions
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
const roomsSchema = `
|
||||
|
@ -31,13 +32,13 @@ const roomsSchema = `
|
|||
latest_event_nids TEXT NOT NULL DEFAULT '[]',
|
||||
last_event_sent_nid INTEGER NOT NULL DEFAULT 0,
|
||||
state_snapshot_nid INTEGER NOT NULL DEFAULT 0,
|
||||
room_version INTEGER NOT NULL DEFAULT 1
|
||||
room_version TEXT NOT NULL
|
||||
);
|
||||
`
|
||||
|
||||
// Same as insertEventTypeNIDSQL
|
||||
const insertRoomNIDSQL = `
|
||||
INSERT INTO roomserver_rooms (room_id) VALUES ($1)
|
||||
INSERT INTO roomserver_rooms (room_id, room_version) VALUES ($1, $2)
|
||||
ON CONFLICT DO NOTHING;
|
||||
`
|
||||
|
||||
|
@ -81,11 +82,12 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) {
|
|||
}
|
||||
|
||||
func (s *roomStatements) insertRoomNID(
|
||||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (types.RoomNID, error) {
|
||||
var err error
|
||||
insertStmt := common.TxStmt(txn, s.insertRoomNIDStmt)
|
||||
if _, err = insertStmt.ExecContext(ctx, roomID); err == nil {
|
||||
if _, err = insertStmt.ExecContext(ctx, roomID, roomVersion); err == nil {
|
||||
return s.selectRoomNID(ctx, txn, roomID)
|
||||
} else {
|
||||
return types.RoomNID(0), err
|
||||
|
@ -157,8 +159,8 @@ func (s *roomStatements) updateLatestEventNIDs(
|
|||
|
||||
func (s *roomStatements) selectRoomVersionForRoomNID(
|
||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
||||
) (int64, error) {
|
||||
var roomVersion int64
|
||||
) (gomatrixserverlib.RoomVersion, error) {
|
||||
var roomVersion gomatrixserverlib.RoomVersion
|
||||
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
||||
return roomVersion, err
|
||||
|
|
|
@ -90,7 +90,8 @@ func (d *Database) StoreEvent(
|
|||
}
|
||||
}
|
||||
|
||||
if roomNID, err = d.assignRoomNID(ctx, txn, event.RoomID()); err != nil {
|
||||
// TODO: Room version here
|
||||
if roomNID, err = d.assignRoomNID(ctx, txn, event.RoomID(), "1"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -150,13 +151,14 @@ func (d *Database) StoreEvent(
|
|||
}
|
||||
|
||||
func (d *Database) assignRoomNID(
|
||||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (roomNID types.RoomNID, err error) {
|
||||
// Check if we already have a numeric ID in the database.
|
||||
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
||||
if err == sql.ErrNoRows {
|
||||
// We don't have a numeric ID so insert one into the database.
|
||||
roomNID, err = d.statements.insertRoomNID(ctx, txn, roomID)
|
||||
roomNID, err = d.statements.insertRoomNID(ctx, txn, roomID, roomVersion)
|
||||
if err == nil {
|
||||
// Now get the numeric ID back out of the database
|
||||
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
||||
|
@ -630,7 +632,8 @@ func (d *Database) MembershipUpdater(
|
|||
}
|
||||
}()
|
||||
|
||||
roomNID, err := d.assignRoomNID(ctx, txn, roomID)
|
||||
// TODO: Room version here
|
||||
roomNID, err := d.assignRoomNID(ctx, txn, roomID, "1")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -853,7 +856,7 @@ func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]type
|
|||
|
||||
func (d *Database) GetRoomVersionForRoom(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (int64, error) {
|
||||
) (gomatrixserverlib.RoomVersion, error) {
|
||||
return d.statements.selectRoomVersionForRoomNID(
|
||||
ctx, nil, roomNID,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue