0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-07-21 10:38:47 +02:00

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
"""
sql = "SELECT %s FROM %s WHERE %s ORDER BY rowid asc" % (
", ".join(retcols),
table,
" AND ".join("%s = ?" % (k, ) for k in keyvalues)
)
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)
txn.execute(sql, keyvalues.values())
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