From 41b641138900781b7974883d8d54b6fbe0d3cd07 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Tue, 8 Aug 2017 18:41:35 +0100 Subject: [PATCH] Rename for more accuracy --- .../roomserver/storage/rooms_table.go | 10 ++++---- .../dendrite/roomserver/storage/storage.go | 25 ++++++------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/rooms_table.go b/src/github.com/matrix-org/dendrite/roomserver/storage/rooms_table.go index 2eae7badd..76b3f67f6 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/rooms_table.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/rooms_table.go @@ -62,7 +62,7 @@ const selectLatestEventNIDsForUpdateSQL = "" + const selectVisibilityForRoomNIDSQL = "" + "SELECT visibility FROM roomserver_rooms WHERE room_nid = $1" -const selectVisibleRoomIDsSQL = "" + +const selectPublicRoomIDsSQL = "" + "SELECT room_id FROM roomserver_rooms WHERE visibility = true" const updateLatestEventNIDsSQL = "" + @@ -77,7 +77,7 @@ type roomStatements struct { selectLatestEventNIDsStmt *sql.Stmt selectLatestEventNIDsForUpdateStmt *sql.Stmt selectVisibilityForRoomNIDStmt *sql.Stmt - selectVisibleRoomIDsStmt *sql.Stmt + selectPublicRoomIDsStmt *sql.Stmt updateLatestEventNIDsStmt *sql.Stmt updateVisibilityForRoomNIDStmt *sql.Stmt } @@ -93,7 +93,7 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) { {&s.selectLatestEventNIDsStmt, selectLatestEventNIDsSQL}, {&s.selectLatestEventNIDsForUpdateStmt, selectLatestEventNIDsForUpdateSQL}, {&s.selectVisibilityForRoomNIDStmt, selectVisibilityForRoomNIDSQL}, - {&s.selectVisibleRoomIDsStmt, selectVisibleRoomIDsSQL}, + {&s.selectPublicRoomIDsStmt, selectPublicRoomIDsSQL}, {&s.updateLatestEventNIDsStmt, updateLatestEventNIDsSQL}, {&s.updateVisibilityForRoomNIDStmt, updateVisibilityForRoomNIDSQL}, }.prepare(db) @@ -148,9 +148,9 @@ func (s *roomStatements) selectVisibilityForRoomNID(roomNID types.RoomNID) (bool return visibility, err } -func (s *roomStatements) selectVisibleRoomIDs() ([]string, error) { +func (s *roomStatements) selectPublicRoomIDs() ([]string, error) { roomIDs := []string{} - rows, err := s.selectVisibleRoomIDsStmt.Query() + rows, err := s.selectPublicRoomIDsStmt.Query() if err != nil { return roomIDs, err } diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/storage.go b/src/github.com/matrix-org/dendrite/roomserver/storage/storage.go index 09f1fe8ff..782da7635 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/storage.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/storage.go @@ -370,9 +370,7 @@ func (d *Database) GetAliasesFromRoomID(roomID string) ([]string, error) { return d.statements.selectAliasesFromRoomID(roomID) } -// GetAliasesFromRoomIDs returns a map of the aliases bound to a given set of -// room IDs, ordered by room ID (ie map[roomID] = []alias) -// Returns an error if the retrieval failed +// GetAliasesFromRoomIDs implements publicroom.RoomserverPublicRoomAPIDB func (d *Database) GetAliasesFromRoomIDs(roomIDs []string) (map[string][]string, error) { return d.statements.selectAliasesFromRoomIDs(roomIDs) } @@ -389,26 +387,17 @@ func (d *Database) StateEntriesForTuples( return d.statements.bulkSelectFilteredStateBlockEntries(stateBlockNIDs, stateKeyTuples) } -// IsRoomVisibleFromRoomNID checks the visibility of the room identified by the -// given numeric ID. Returns true if the room is publicly visible, returns false -// if not. -// If there's no room matching this numeric ID, or if the retrieval failed, -// returns an error. -func (d *Database) IsRoomVisibleFromRoomNID(roomNID types.RoomNID) (bool, error) { +// IsRoomPublic implements publicroom.RoomserverPublicRoomAPIDB +func (d *Database) IsRoomPublic(roomNID types.RoomNID) (bool, error) { return d.statements.selectVisibilityForRoomNID(roomNID) } -// GetVisibleRoomIDs returns an array of string containing the room IDs of the -// rooms that are publicly visible. -// Returns an error if the retrieval failed. -func (d *Database) GetVisibleRoomIDs() ([]string, error) { - return d.statements.selectVisibleRoomIDs() +// GetPublicRoomIDs implements publicroom.RoomserverPublicRoomAPIDB +func (d *Database) GetPublicRoomIDs() ([]string, error) { + return d.statements.selectPublicRoomIDs() } -// UpdateRoomVisibility updates the visibility for a room to the given value: -// true means that the room is publicly visible, false means that the room isn't -// publicly visible. -// Returns an error if the update failed. +// UpdateRoomVisibility implements publicroom.RoomserverPublicRoomAPIDB func (d *Database) UpdateRoomVisibility(roomNID types.RoomNID, visibility bool) error { return d.statements.updateVisibilityForRoomNID(roomNID, visibility) }