summary refs log tree commit diff
path: root/synapse/push/action_generator.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-12-22 15:19:34 +0000
committerDavid Baker <dave@matrix.org>2015-12-22 15:19:34 +0000
commit65c451cb3878fb41f28a2adecd638894e18f5343 (patch)
treea7c6e22972510035bf3e7dda921a19eb7c70cee2 /synapse/push/action_generator.py
parentMerge remote-tracking branch 'origin/develop' into store_event_actions (diff)
downloadsynapse-65c451cb3878fb41f28a2adecd638894e18f5343.tar.xz
Add bulk push rule evaluator which actually still evaluates rules one by one, but does far fewer db queries to fetch the rules
Diffstat (limited to 'synapse/push/action_generator.py')
-rw-r--r--synapse/push/action_generator.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/synapse/push/action_generator.py b/synapse/push/action_generator.py
index 6e107ca792..2ad5f82da2 100644
--- a/synapse/push/action_generator.py
+++ b/synapse/push/action_generator.py
@@ -15,9 +15,7 @@
 
 from twisted.internet import defer
 
-from synapse.types import UserID
-
-import push_rule_evaluator
+import bulk_push_rule_evaluator
 
 import logging
 
@@ -39,17 +37,13 @@ class ActionGenerator:
     def handle_event(self, event):
         users = yield self.store.get_users_in_room(event['room_id'])
 
-        for uid in users:
-            if not self.hs.is_mine(UserID.from_string(uid)):
-                continue
-
-            evaluator = yield push_rule_evaluator.\
-                evaluator_for_user_name_and_profile_tag(
-                    uid, None, event['room_id'], self.store
-                )
-            actions = yield evaluator.actions_for_event(event)
-            logger.info("actions for user %s: %s", uid, actions)
-            if len(actions):
-                self.store.set_actions_for_event(
-                    event, uid, None, actions
-                )
+        bulk_evaluator = yield bulk_push_rule_evaluator.evaluator_for_room_id(
+            event['room_id'], self.hs, self.store
+        )
+
+        actions_by_user = bulk_evaluator.action_for_event_by_user(event)
+
+        for uid,actions in actions_by_user.items():
+            self.store.set_actions_for_event(
+                event, uid, None, actions
+            )