mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-18 08:54:54 +03:00
Since store.get_rooms() is only ever called with is_public=True, just fold that inline + rename the method to .get_published_rooms()
This commit is contained in:
parent
4909cd0202
commit
7c5315b1a8
4 changed files with 11 additions and 15 deletions
|
@ -533,7 +533,7 @@ class RoomListHandler(BaseHandler):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def get_published_rooms(self):
|
||||
chunk = yield self.store.get_rooms(is_public=True)
|
||||
chunk = yield self.store.get_published_rooms()
|
||||
results = yield defer.gatherResults(
|
||||
[
|
||||
self.store.get_users_in_room(room["room_id"])
|
||||
|
|
|
@ -147,8 +147,7 @@ class SyncHandler(BaseHandler):
|
|||
membership_list=[Membership.INVITE, Membership.JOIN]
|
||||
)
|
||||
|
||||
# TODO (mjark): Does public mean "published"?
|
||||
published_rooms = yield self.store.get_rooms(is_public=True)
|
||||
published_rooms = yield self.store.get_published_rooms()
|
||||
published_room_ids = set(r["room_id"] for r in published_rooms)
|
||||
|
||||
rooms = []
|
||||
|
@ -231,8 +230,7 @@ class SyncHandler(BaseHandler):
|
|||
rm_handler = self.hs.get_handlers().room_member_handler
|
||||
room_ids = yield rm_handler.get_joined_rooms_for_user(sync_config.user)
|
||||
|
||||
# TODO (mjark): Does public mean "published"?
|
||||
published_rooms = yield self.store.get_rooms(is_public=True)
|
||||
published_rooms = yield self.store.get_published_rooms()
|
||||
published_room_ids = set(r["room_id"] for r in published_rooms)
|
||||
|
||||
room_events, _ = yield self.store.get_room_events_stream(
|
||||
|
|
|
@ -86,11 +86,9 @@ class RoomStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_rooms(self, is_public):
|
||||
"""Retrieve a list of all public rooms.
|
||||
def get_published_rooms(self):
|
||||
"""Retrieve a list of all published rooms.
|
||||
|
||||
Args:
|
||||
is_public (bool): True if the rooms returned should be public.
|
||||
Returns:
|
||||
A list of room dicts containing at least a "room_id" key, a
|
||||
"topic" key if one is set, and a "name" key if one is set
|
||||
|
@ -119,14 +117,14 @@ class RoomStore(SQLBaseStore):
|
|||
" FROM rooms AS r"
|
||||
" LEFT JOIN (%(topic)s) AS t ON t.room_id = r.room_id"
|
||||
" LEFT JOIN (%(name)s) AS n ON n.room_id = r.room_id"
|
||||
" WHERE r.is_public = ?"
|
||||
" WHERE r.is_public"
|
||||
" GROUP BY r.room_id"
|
||||
) % {
|
||||
"topic": topic_subquery,
|
||||
"name": name_subquery,
|
||||
}
|
||||
|
||||
txn.execute(sql, (is_public,))
|
||||
txn.execute(sql)
|
||||
|
||||
rows = txn.fetchall()
|
||||
|
||||
|
|
|
@ -52,10 +52,10 @@ class RoomStoreTestCase(unittest.TestCase):
|
|||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_get_rooms(self):
|
||||
# get_rooms does an INNER JOIN on the room_aliases table :(
|
||||
def test_get_published_rooms(self):
|
||||
# get_published_rooms does an INNER JOIN on the room_aliases table :(
|
||||
|
||||
rooms = yield self.store.get_rooms(is_public=True)
|
||||
rooms = yield self.store.get_published_rooms()
|
||||
# Should be empty before we add the alias
|
||||
self.assertEquals([], rooms)
|
||||
|
||||
|
@ -65,7 +65,7 @@ class RoomStoreTestCase(unittest.TestCase):
|
|||
servers=["test"]
|
||||
)
|
||||
|
||||
rooms = yield self.store.get_rooms(is_public=True)
|
||||
rooms = yield self.store.get_published_rooms()
|
||||
|
||||
self.assertEquals(1, len(rooms))
|
||||
self.assertEquals({
|
||||
|
|
Loading…
Reference in a new issue