summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2017-10-05 13:20:22 +0100
committerDavid Baker <dave@matrix.org>2017-10-05 13:20:22 +0100
commited80c6b6cc6da27849038a1b83bec7fa1ac54b3e (patch)
tree0782a048c7d808da4b6486c1e65c3e6ecf3c45d8
parentpep8 (diff)
downloadsynapse-ed80c6b6cc6da27849038a1b83bec7fa1ac54b3e.tar.xz
Add fastpath optimisation
-rw-r--r--synapse/push/bulk_push_rule_evaluator.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py
index 6459eec225..ca3b5af807 100644
--- a/synapse/push/bulk_push_rule_evaluator.py
+++ b/synapse/push/bulk_push_rule_evaluator.py
@@ -112,9 +112,15 @@ class BulkPushRuleEvaluator(object):
 
     @defer.inlineCallbacks
     def _get_sender_power_level(self, event, context):
-        auth_events_ids = yield self.auth.compute_auth_events(
-            event, context.prev_state_ids, for_verification=False,
-        )
+        pl_event_key = (EventTypes.PowerLevels, "", )
+        if pl_event_key in context.prev_state_ids:
+            # fastpath: if there's a power level event, that's all we need, and
+            # not having a power level event is an extreme edge case
+            auth_events_ids = [context.prev_state_ids[pl_event_key]]
+        else:
+            auth_events_ids = yield self.auth.compute_auth_events(
+                event, context.prev_state_ids, for_verification=False,
+            )
         auth_events = yield self.store.get_events(auth_events_ids)
         auth_events = {
             (e.type, e.state_key): e for e in auth_events.values()