mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-18 12:23:09 -06:00
Fix database wrapping, add comments for version descriptions
This commit is contained in:
parent
492980e098
commit
288a1bff5f
|
|
@ -93,11 +93,12 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomStatements) insertRoomNID(
|
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) {
|
) (types.RoomNID, error) {
|
||||||
var roomNID int64
|
var roomNID int64
|
||||||
stmt := common.TxStmt(txn, s.insertRoomNIDStmt)
|
stmt := common.TxStmt(txn, s.insertRoomNIDStmt)
|
||||||
err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID)
|
err := stmt.QueryRowContext(ctx, roomID, roomVersion).Scan(&roomNID)
|
||||||
return types.RoomNID(roomNID), err
|
return types.RoomNID(roomNID), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ func (d *Database) StoreEvent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if roomNID, err = d.assignRoomNID(ctx, nil, event.RoomID()); err != nil {
|
// TODO: Room version here
|
||||||
|
if roomNID, err = d.assignRoomNID(ctx, nil, event.RoomID(), "1"); err != nil {
|
||||||
return 0, types.StateAtEvent{}, err
|
return 0, types.StateAtEvent{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,13 +122,14 @@ func (d *Database) StoreEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) assignRoomNID(
|
func (d *Database) assignRoomNID(
|
||||||
ctx context.Context, txn *sql.Tx, roomID string,
|
ctx context.Context, txn *sql.Tx,
|
||||||
|
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (types.RoomNID, error) {
|
) (types.RoomNID, error) {
|
||||||
// Check if we already have a numeric ID in the database.
|
// Check if we already have a numeric ID in the database.
|
||||||
roomNID, err := d.statements.selectRoomNID(ctx, txn, roomID)
|
roomNID, err := d.statements.selectRoomNID(ctx, txn, roomID)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
// We don't have a numeric ID so insert one into the database.
|
// 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 == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
// We raced with another insert so run the select again.
|
// We raced with another insert so run the select again.
|
||||||
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
||||||
|
|
@ -494,7 +496,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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,11 +82,12 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomStatements) insertRoomNID(
|
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) {
|
) (types.RoomNID, error) {
|
||||||
var err error
|
var err error
|
||||||
insertStmt := common.TxStmt(txn, s.insertRoomNIDStmt)
|
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)
|
return s.selectRoomNID(ctx, txn, roomID)
|
||||||
} else {
|
} else {
|
||||||
return types.RoomNID(0), err
|
return types.RoomNID(0), 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,13 +151,14 @@ func (d *Database) StoreEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) assignRoomNID(
|
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) {
|
) (roomNID types.RoomNID, err error) {
|
||||||
// Check if we already have a numeric ID in the database.
|
// Check if we already have a numeric ID in the database.
|
||||||
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
// We don't have a numeric ID so insert one into the database.
|
// 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 {
|
if err == nil {
|
||||||
// Now get the numeric ID back out of the database
|
// Now get the numeric ID back out of the database
|
||||||
roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@ import (
|
||||||
// RoomVersionDescription contains information about a room version,
|
// RoomVersionDescription contains information about a room version,
|
||||||
// namely whether it is marked as supported or stable in this server
|
// namely whether it is marked as supported or stable in this server
|
||||||
// version.
|
// version.
|
||||||
|
// A version is supported if the server has some support for rooms
|
||||||
|
// that are this version. A version is marked as stable or unstable
|
||||||
|
// in order to hint whether the version should be used to clients
|
||||||
|
// calling the /capabilities endpoint.
|
||||||
|
// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities
|
||||||
type RoomVersionDescription struct {
|
type RoomVersionDescription struct {
|
||||||
Supported bool
|
Supported bool
|
||||||
Stable bool
|
Stable bool
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue