summary refs log tree commit diff
path: root/synapse/push/action_generator.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-05-02 10:46:01 +0100
committerErik Johnston <erik@matrix.org>2017-05-17 16:55:40 +0100
commit66d8ffabbdfa1fadd107851c8a0362a74149b37b (patch)
treef343c2eebce037e480dddc8f02f86b0a64f6fd24 /synapse/push/action_generator.py
parentMerge pull request #2216 from slipeer/app_services_interested_in_user (diff)
downloadsynapse-66d8ffabbdfa1fadd107851c8a0362a74149b37b.tar.xz
Faster push rule calculation via push specific cache
We add a push rule specific cache that ensures that we can reuse
calculated push rules appropriately when a user join/leaves.
Diffstat (limited to 'synapse/push/action_generator.py')
-rw-r--r--synapse/push/action_generator.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/synapse/push/action_generator.py b/synapse/push/action_generator.py
index 3f75d3f921..0658497d9b 100644
--- a/synapse/push/action_generator.py
+++ b/synapse/push/action_generator.py
@@ -15,7 +15,7 @@
 
 from twisted.internet import defer
 
-from .bulk_push_rule_evaluator import evaluator_for_event
+from .bulk_push_rule_evaluator import BulkPushRuleEvaluator
 
 from synapse.util.metrics import Measure
 
@@ -29,6 +29,7 @@ class ActionGenerator:
         self.hs = hs
         self.clock = hs.get_clock()
         self.store = hs.get_datastore()
+        self.bulk_evaluator = BulkPushRuleEvaluator(hs)
         # really we want to get all user ids and all profile tags too,
         # since we want the actions for each profile tag for every user and
         # also actions for a client with no profile tag for each user.
@@ -38,16 +39,11 @@ class ActionGenerator:
 
     @defer.inlineCallbacks
     def handle_push_actions_for_event(self, event, context):
-        with Measure(self.clock, "evaluator_for_event"):
-            bulk_evaluator = yield evaluator_for_event(
-                event, self.hs, self.store, context
-            )
-
         with Measure(self.clock, "action_for_event_by_user"):
-            actions_by_user = yield bulk_evaluator.action_for_event_by_user(
+            actions_by_user = yield self.bulk_evaluator.action_for_event_by_user(
                 event, context
             )
 
         context.push_actions = [
-            (uid, actions) for uid, actions in actions_by_user.items()
+            (uid, actions) for uid, actions in actions_by_user.iteritems()
         ]