Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Speed up calculating push rules #2238

Merged
merged 3 commits into from
May 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ def __init__(self, hs, room_id, rules_for_room_cache):
# not update the cache with it.
self.sequence = 0

# A cache of user_ids that we *know* aren't interesting, e.g. user_ids
# owned by AS's, or remote users, etc. (I.e. users we will never need to
# calculate push for)
# These never need to be invalidated as we will never set up push for
# them.
self.uninteresting_user_set = set()

# We need to be clever on the invalidating caches callbacks, as
# otherwise the invalidation callback holds a reference to the object,
# potentially causing it to leak.
Expand Down Expand Up @@ -231,10 +238,24 @@ def get_rules(self, context):

# Loop through to see which member events we've seen and have rules
# for and which we need to fetch
for key, event_id in current_state_ids.iteritems():
if key[0] != EventTypes.Member:
for key in current_state_ids:
typ, user_id = key
if typ != EventTypes.Member:
continue

if user_id in self.uninteresting_user_set:
continue

if not self.is_mine_id(user_id):
self.uninteresting_user_set.add(user_id)
continue

if self.store.get_if_app_services_interested_in_user(user_id):
self.uninteresting_user_set.add(user_id)
continue

event_id = current_state_ids[key]

res = self.member_map.get(event_id, None)
if res:
user_id, state = res
Expand All @@ -244,13 +265,6 @@ def get_rules(self, context):
ret_rules_by_user[user_id] = rules
continue

user_id = key[1]
if not self.is_mine_id(user_id):
continue

if self.store.get_if_app_services_interested_in_user(user_id):
continue

# If a user has left a room we remove their push rule. If they
# joined then we readd it later in _update_rules_with_member_event_ids
ret_rules_by_user.pop(user_id, None)
Expand Down