mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 22:02:46 +00:00
Add RoomInfo metadata struct (#1367)
* Add RoomInfo struct * Remove RoomNID and replace with RoomInfo * Bugfix and remove another needless query * nil guard
This commit is contained in:
parent
0ab5bccd11
commit
6d79f04354
10 changed files with 106 additions and 85 deletions
|
@ -74,6 +74,9 @@ const selectRoomVersionForRoomIDSQL = "" +
|
|||
const selectRoomVersionForRoomNIDSQL = "" +
|
||||
"SELECT room_version FROM roomserver_rooms WHERE room_nid = $1"
|
||||
|
||||
const selectRoomInfoSQL = "" +
|
||||
"SELECT room_version, room_nid, state_snapshot_nid, latest_event_nids FROM roomserver_rooms WHERE room_id = $1"
|
||||
|
||||
type roomStatements struct {
|
||||
insertRoomNIDStmt *sql.Stmt
|
||||
selectRoomNIDStmt *sql.Stmt
|
||||
|
@ -82,6 +85,7 @@ type roomStatements struct {
|
|||
updateLatestEventNIDsStmt *sql.Stmt
|
||||
selectRoomVersionForRoomIDStmt *sql.Stmt
|
||||
selectRoomVersionForRoomNIDStmt *sql.Stmt
|
||||
selectRoomInfoStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func NewPostgresRoomsTable(db *sql.DB) (tables.Rooms, error) {
|
||||
|
@ -98,6 +102,7 @@ func NewPostgresRoomsTable(db *sql.DB) (tables.Rooms, error) {
|
|||
{&s.updateLatestEventNIDsStmt, updateLatestEventNIDsSQL},
|
||||
{&s.selectRoomVersionForRoomIDStmt, selectRoomVersionForRoomIDSQL},
|
||||
{&s.selectRoomVersionForRoomNIDStmt, selectRoomVersionForRoomNIDSQL},
|
||||
{&s.selectRoomInfoStmt, selectRoomInfoSQL},
|
||||
}.Prepare(db)
|
||||
}
|
||||
|
||||
|
@ -111,6 +116,19 @@ func (s *roomStatements) InsertRoomNID(
|
|||
return types.RoomNID(roomNID), err
|
||||
}
|
||||
|
||||
func (s *roomStatements) SelectRoomInfo(ctx context.Context, roomID string) (*types.RoomInfo, error) {
|
||||
var info types.RoomInfo
|
||||
var latestNIDs pq.Int64Array
|
||||
err := s.selectRoomInfoStmt.QueryRowContext(ctx, roomID).Scan(
|
||||
&info.RoomVersion, &info.RoomNID, &info.StateSnapshotNID, &latestNIDs,
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
info.IsStub = len(latestNIDs) == 0
|
||||
return &info, err
|
||||
}
|
||||
|
||||
func (s *roomStatements) SelectRoomNID(
|
||||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
) (types.RoomNID, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue