Modify _simple_select_list to allow an empty WHERE clause. Use it for get_all_rooms and get_all_users.

This commit is contained in:
Kegan Dougal 2015-03-02 10:16:24 +00:00
parent ebc4830666
commit 3d73383d18
4 changed files with 21 additions and 17 deletions

View File

@ -450,7 +450,8 @@ class SQLBaseStore(object):
Args:
table : string giving the table name
keyvalues : dict of column names and values to select the rows with
keyvalues : dict of column names and values to select the rows with,
or None to not apply a WHERE clause.
retcols : list of strings giving the names of the columns to return
"""
return self.runInteraction(
@ -469,13 +470,20 @@ class SQLBaseStore(object):
keyvalues : dict of column names and values to select the rows with
retcols : list of strings giving the names of the columns to return
"""
if keyvalues:
sql = "SELECT %s FROM %s WHERE %s ORDER BY rowid asc" % (
", ".join(retcols),
table,
" AND ".join("%s = ?" % (k, ) for k in keyvalues)
)
txn.execute(sql, keyvalues.values())
else:
sql = "SELECT %s FROM %s ORDER BY rowid asc" % (
", ".join(retcols),
table
)
txn.execute(sql)
return self.cursor_to_dict(txn)
def _simple_update_one(self, table, keyvalues, updatevalues,

View File

@ -220,8 +220,8 @@ class ApplicationServiceStore(SQLBaseStore):
# get all rooms matching the room ID regex.
room_entries = yield self.get_all_rooms() # RoomEntry list
matching_room_list = set([
r.room_id for r in room_entries if
service.is_interested_in_room(r.room_id)
r["room_id"] for r in room_entries if
service.is_interested_in_room(r["room_id"])
])
# resolve room IDs for matching room alias regex.

View File

@ -93,11 +93,8 @@ class RegistrationStore(SQLBaseStore):
)
def get_all_users(self):
query = "SELECT users.name FROM users"
return self._execute(
self.cursor_to_dict,
query
)
return self._simple_select_list(
table="users", keyvalues=None, retcols=["name"])
def get_user_by_token(self, token):
"""Get a user from the given access token.

View File

@ -77,9 +77,8 @@ class RoomStore(SQLBaseStore):
Returns:
A list of namedtuples containing the room information.
"""
query = RoomsTable.select_statement()
return self._execute(
RoomsTable.decode_results, query,
return self._simple_select_list(
table="rooms", keyvalues=None, retcols=["room_id"]
)
@defer.inlineCallbacks