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:
Paul "LeoNerd" Evans 2015-06-18 14:15:20 +01:00
parent 4909cd0202
commit 7c5315b1a8
4 changed files with 11 additions and 15 deletions

View file

@ -533,7 +533,7 @@ class RoomListHandler(BaseHandler):
@defer.inlineCallbacks @defer.inlineCallbacks
def get_published_rooms(self): 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( results = yield defer.gatherResults(
[ [
self.store.get_users_in_room(room["room_id"]) self.store.get_users_in_room(room["room_id"])

View file

@ -147,8 +147,7 @@ class SyncHandler(BaseHandler):
membership_list=[Membership.INVITE, Membership.JOIN] membership_list=[Membership.INVITE, Membership.JOIN]
) )
# TODO (mjark): Does public mean "published"? published_rooms = yield self.store.get_published_rooms()
published_rooms = yield self.store.get_rooms(is_public=True)
published_room_ids = set(r["room_id"] for r in published_rooms) published_room_ids = set(r["room_id"] for r in published_rooms)
rooms = [] rooms = []
@ -231,8 +230,7 @@ class SyncHandler(BaseHandler):
rm_handler = self.hs.get_handlers().room_member_handler rm_handler = self.hs.get_handlers().room_member_handler
room_ids = yield rm_handler.get_joined_rooms_for_user(sync_config.user) 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_published_rooms()
published_rooms = yield self.store.get_rooms(is_public=True)
published_room_ids = set(r["room_id"] for r in published_rooms) published_room_ids = set(r["room_id"] for r in published_rooms)
room_events, _ = yield self.store.get_room_events_stream( room_events, _ = yield self.store.get_room_events_stream(

View file

@ -86,11 +86,9 @@ class RoomStore(SQLBaseStore):
) )
@defer.inlineCallbacks @defer.inlineCallbacks
def get_rooms(self, is_public): def get_published_rooms(self):
"""Retrieve a list of all public rooms. """Retrieve a list of all published rooms.
Args:
is_public (bool): True if the rooms returned should be public.
Returns: Returns:
A list of room dicts containing at least a "room_id" key, a 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 "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" " FROM rooms AS r"
" LEFT JOIN (%(topic)s) AS t ON t.room_id = r.room_id" " 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" " 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" " GROUP BY r.room_id"
) % { ) % {
"topic": topic_subquery, "topic": topic_subquery,
"name": name_subquery, "name": name_subquery,
} }
txn.execute(sql, (is_public,)) txn.execute(sql)
rows = txn.fetchall() rows = txn.fetchall()

View file

@ -52,10 +52,10 @@ class RoomStoreTestCase(unittest.TestCase):
) )
@defer.inlineCallbacks @defer.inlineCallbacks
def test_get_rooms(self): def test_get_published_rooms(self):
# get_rooms does an INNER JOIN on the room_aliases table :( # 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 # Should be empty before we add the alias
self.assertEquals([], rooms) self.assertEquals([], rooms)
@ -65,7 +65,7 @@ class RoomStoreTestCase(unittest.TestCase):
servers=["test"] 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(1, len(rooms))
self.assertEquals({ self.assertEquals({