0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-17 19:53:52 +01:00

Speed up calculating push rules

This commit is contained in:
Erik Johnston 2017-05-19 16:51:05 +01:00
parent ab4ee2e524
commit 270e1c904a

View file

@ -200,6 +200,10 @@ class RulesForRoom(object):
# not update the cache with it. # not update the cache with it.
self.sequence = 0 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.
self.uninteresting_user_set = set()
# We need to be clever on the invalidating caches callbacks, as # We need to be clever on the invalidating caches callbacks, as
# otherwise the invalidation callback holds a reference to the object, # otherwise the invalidation callback holds a reference to the object,
# potentially causing it to leak. # potentially causing it to leak.
@ -231,10 +235,24 @@ class RulesForRoom(object):
# Loop through to see which member events we've seen and have rules # Loop through to see which member events we've seen and have rules
# for and which we need to fetch # for and which we need to fetch
for key, event_id in current_state_ids.iteritems(): for key in current_state_ids:
if key[0] != EventTypes.Member: if key[0] != EventTypes.Member:
continue continue
user_id = key[1]
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) res = self.member_map.get(event_id, None)
if res: if res:
user_id, state = res user_id, state = res
@ -244,13 +262,6 @@ class RulesForRoom(object):
ret_rules_by_user[user_id] = rules ret_rules_by_user[user_id] = rules
continue 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 # 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 # joined then we readd it later in _update_rules_with_member_event_ids
ret_rules_by_user.pop(user_id, None) ret_rules_by_user.pop(user_id, None)