forked from MirrorHub/synapse
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:
parent
ebc4830666
commit
3d73383d18
4 changed files with 21 additions and 17 deletions
|
@ -450,7 +450,8 @@ class SQLBaseStore(object):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
table : string giving the table name
|
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
|
retcols : list of strings giving the names of the columns to return
|
||||||
"""
|
"""
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
|
@ -469,13 +470,20 @@ class SQLBaseStore(object):
|
||||||
keyvalues : dict of column names and values to select the rows with
|
keyvalues : dict of column names and values to select the rows with
|
||||||
retcols : list of strings giving the names of the columns to return
|
retcols : list of strings giving the names of the columns to return
|
||||||
"""
|
"""
|
||||||
sql = "SELECT %s FROM %s WHERE %s ORDER BY rowid asc" % (
|
if keyvalues:
|
||||||
", ".join(retcols),
|
sql = "SELECT %s FROM %s WHERE %s ORDER BY rowid asc" % (
|
||||||
table,
|
", ".join(retcols),
|
||||||
" AND ".join("%s = ?" % (k, ) for k in keyvalues)
|
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)
|
return self.cursor_to_dict(txn)
|
||||||
|
|
||||||
def _simple_update_one(self, table, keyvalues, updatevalues,
|
def _simple_update_one(self, table, keyvalues, updatevalues,
|
||||||
|
|
|
@ -220,8 +220,8 @@ class ApplicationServiceStore(SQLBaseStore):
|
||||||
# get all rooms matching the room ID regex.
|
# get all rooms matching the room ID regex.
|
||||||
room_entries = yield self.get_all_rooms() # RoomEntry list
|
room_entries = yield self.get_all_rooms() # RoomEntry list
|
||||||
matching_room_list = set([
|
matching_room_list = set([
|
||||||
r.room_id for r in room_entries if
|
r["room_id"] for r in room_entries if
|
||||||
service.is_interested_in_room(r.room_id)
|
service.is_interested_in_room(r["room_id"])
|
||||||
])
|
])
|
||||||
|
|
||||||
# resolve room IDs for matching room alias regex.
|
# resolve room IDs for matching room alias regex.
|
||||||
|
|
|
@ -93,11 +93,8 @@ class RegistrationStore(SQLBaseStore):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_all_users(self):
|
def get_all_users(self):
|
||||||
query = "SELECT users.name FROM users"
|
return self._simple_select_list(
|
||||||
return self._execute(
|
table="users", keyvalues=None, retcols=["name"])
|
||||||
self.cursor_to_dict,
|
|
||||||
query
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_user_by_token(self, token):
|
def get_user_by_token(self, token):
|
||||||
"""Get a user from the given access token.
|
"""Get a user from the given access token.
|
||||||
|
|
|
@ -77,9 +77,8 @@ class RoomStore(SQLBaseStore):
|
||||||
Returns:
|
Returns:
|
||||||
A list of namedtuples containing the room information.
|
A list of namedtuples containing the room information.
|
||||||
"""
|
"""
|
||||||
query = RoomsTable.select_statement()
|
return self._simple_select_list(
|
||||||
return self._execute(
|
table="rooms", keyvalues=None, retcols=["room_id"]
|
||||||
RoomsTable.decode_results, query,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in a new issue