diff options
author | Kegsay <kegan@matrix.org> | 2020-09-01 12:40:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-01 12:40:49 +0100 |
commit | 6d79f043541f522207f298d0f585c01e74e1177d (patch) | |
tree | 7509c9f1407bd9592de75f1b76d199cc9a2c9839 /roomserver/storage/postgres/rooms_table.go | |
parent | 0ab5bccd11eea6063968c60fbdf5b36ade22da81 (diff) |
Add RoomInfo metadata struct (#1367)
* Add RoomInfo struct
* Remove RoomNID and replace with RoomInfo
* Bugfix and remove another needless query
* nil guard
Diffstat (limited to 'roomserver/storage/postgres/rooms_table.go')
-rw-r--r-- | roomserver/storage/postgres/rooms_table.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/roomserver/storage/postgres/rooms_table.go b/roomserver/storage/postgres/rooms_table.go index 8e00cfdb..691c04ba 100644 --- a/roomserver/storage/postgres/rooms_table.go +++ b/roomserver/storage/postgres/rooms_table.go @@ -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) { |