mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Adjust InsertRoomNID
This commit is contained in:
parent
f37bd0156f
commit
824f499a70
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||||
|
|
@ -98,17 +99,23 @@ func NewSqliteRoomsTable(db *sql.DB) (tables.Rooms, error) {
|
||||||
func (s *roomStatements) InsertRoomNID(
|
func (s *roomStatements) InsertRoomNID(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (types.RoomNID, error) {
|
) (roomNID types.RoomNID, err error) {
|
||||||
err := s.writer.Do(s.db, txn, func(txn *sql.Tx) error {
|
err = s.writer.Do(s.db, txn, func(txn *sql.Tx) error {
|
||||||
insertStmt := sqlutil.TxStmt(txn, s.insertRoomNIDStmt)
|
insertStmt := sqlutil.TxStmt(txn, s.insertRoomNIDStmt)
|
||||||
_, err := insertStmt.ExecContext(ctx, roomID, roomVersion)
|
_, err = insertStmt.ExecContext(ctx, roomID, roomVersion)
|
||||||
return err
|
if err != nil {
|
||||||
|
return fmt.Errorf("insertStmt.ExecContext: %w", err)
|
||||||
|
}
|
||||||
|
roomNID, err = s.SelectRoomNID(ctx, txn, roomID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("s.SelectRoomNID: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
return s.SelectRoomNID(ctx, txn, roomID)
|
|
||||||
} else {
|
|
||||||
return types.RoomNID(0), err
|
return types.RoomNID(0), err
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomStatements) SelectRoomNID(
|
func (s *roomStatements) SelectRoomNID(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue