Replace context.current_state with context.current_state_ids

This commit is contained in:
Erik Johnston 2016-08-25 17:32:22 +01:00
parent 17f4f14df7
commit a3dc1e9cbe
15 changed files with 435 additions and 270 deletions

View file

@ -124,7 +124,8 @@ class PushRuleStore(SQLBaseStore):
defer.returnValue(results)
def bulk_get_push_rules_for_room(self, room_id, state_group, current_state):
def bulk_get_push_rules_for_room(self, room_id, context):
state_group = context.state_group
if not state_group:
# If state_group is None it means it has yet to be assigned a
# state group, i.e. we need to make sure that calls with a state_group
@ -132,10 +133,12 @@ class PushRuleStore(SQLBaseStore):
# To do this we set the state_group to a new object as object() != object()
state_group = object()
return self._bulk_get_push_rules_for_room(room_id, state_group, current_state)
return self._bulk_get_push_rules_for_room(
room_id, state_group, context.current_state_ids
)
@cachedInlineCallbacks(num_args=2, cache_context=True)
def _bulk_get_push_rules_for_room(self, room_id, state_group, current_state,
def _bulk_get_push_rules_for_room(self, room_id, state_group, current_state_ids,
cache_context):
# We don't use `state_group`, its there so that we can cache based
# on it. However, its important that its never None, since two current_state's
@ -147,10 +150,16 @@ class PushRuleStore(SQLBaseStore):
# their unread countss are correct in the event stream, but to avoid
# generating them for bot / AS users etc, we only do so for people who've
# sent a read receipt into the room.
local_user_member_ids = [
e_id for (etype, state_key), e_id in current_state_ids.iteritems()
if etype == EventTypes.Member and self.hs.is_mine_id(state_key)
]
local_member_events = yield self._get_events(local_user_member_ids)
local_users_in_room = set(
e.state_key for e in current_state.values()
if e.type == EventTypes.Member and e.membership == Membership.JOIN
and self.hs.is_mine_id(e.state_key)
member_event.state_key for member_event in local_member_events
if member_event.membership == Membership.JOIN
)
# users in the room who have pushers need to get push rules run because