We don't need the full events for get_rooms_for_user_where_membership_is

This commit is contained in:
Erik Johnston 2015-01-06 14:37:00 +00:00
parent af1c7c7808
commit 76ec154e95
2 changed files with 36 additions and 10 deletions

View file

@ -16,7 +16,7 @@
from twisted.internet import defer
from synapse.api.errors import SynapseError, AuthError, CodeMessageException
from synapse.api.constants import Membership
from synapse.api.constants import EventTypes, Membership
from synapse.util.logcontext import PreserveLoggingContext
from ._base import BaseHandler
@ -203,7 +203,7 @@ class ProfileHandler(BaseHandler):
for j in joins:
content = {
"membership": j.content["membership"],
"membership": Membership.JOIN,
}
yield self.distributor.fire(
@ -212,9 +212,9 @@ class ProfileHandler(BaseHandler):
msg_handler = self.hs.get_handlers().message_handler
yield msg_handler.create_and_send_event({
"type": j.type,
"type": EventTypes.Member,
"room_id": j.room_id,
"state_key": j.state_key,
"state_key": user.to_string(),
"content": content,
"sender": j.state_key
"sender": user.to_string()
}, ratelimit=False)

View file

@ -15,6 +15,8 @@
from twisted.internet import defer
from collections import namedtuple
from ._base import SQLBaseStore
from synapse.api.constants import Membership
@ -24,6 +26,12 @@ import logging
logger = logging.getLogger(__name__)
RoomsForUser = namedtuple(
"RoomsForUser",
("room_id", "sender", "membership")
)
class RoomMemberStore(SQLBaseStore):
def _store_room_member_txn(self, txn, event):
@ -163,19 +171,37 @@ class RoomMemberStore(SQLBaseStore):
membership_list (list): A list of synapse.api.constants.Membership
values which the user must be in.
Returns:
A list of RoomMemberEvent objects
A list of dictionary objects, with room_id, membership and sender
defined.
"""
if not membership_list:
return defer.succeed(None)
args = [user_id]
args.extend(membership_list)
where_clause = "user_id = ? AND (%s)" % (
" OR ".join(["membership = ?" for _ in membership_list]),
)
return self._get_members_query(where_clause, args)
args = [user_id]
args.extend(membership_list)
def f(txn):
sql = (
"SELECT m.room_id, m.sender, m.membership"
" FROM room_memberships as m"
" INNER JOIN current_state_events as c"
" ON m.event_id = c.event_id"
" WHERE %s"
) % (where_clause,)
txn.execute(sql, args)
return [
RoomsForUser(**r) for r in self.cursor_to_dict(txn)
]
return self.runInteraction(
"get_rooms_for_user_where_membership_is",
f
)
def get_joined_hosts_for_room(self, room_id):
return self._simple_select_onecol(