summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-12-22 17:04:31 +0000
committerDavid Baker <dave@matrix.org>2015-12-22 17:04:31 +0000
commit4c8f6a7e427cc0e22ff1a19c3f1d9da0f9438f18 (patch)
tree9033a7a82ff6f7339f654af6d7589b3a29bc1658
parentclarify problems (diff)
downloadsynapse-4c8f6a7e427cc0e22ff1a19c3f1d9da0f9438f18.tar.xz
Insert push actions in a single db query rather than one per user/profile_tag
-rw-r--r--synapse/push/action_generator.py10
-rw-r--r--synapse/storage/event_actions.py31
2 files changed, 24 insertions, 17 deletions
diff --git a/synapse/push/action_generator.py b/synapse/push/action_generator.py
index 2ad5f82da2..148b1bda8e 100644
--- a/synapse/push/action_generator.py
+++ b/synapse/push/action_generator.py
@@ -43,7 +43,9 @@ class ActionGenerator:
 
         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
-            )
+        yield self.store.set_actions_for_event_and_users(
+            event,
+            [
+                (uid, None, actions) for uid, actions in actions_by_user.items()
+            ]
+        )
diff --git a/synapse/storage/event_actions.py b/synapse/storage/event_actions.py
index fbd0a42279..3efa445c18 100644
--- a/synapse/storage/event_actions.py
+++ b/synapse/storage/event_actions.py
@@ -24,22 +24,27 @@ logger = logging.getLogger(__name__)
 
 class EventActionsStore(SQLBaseStore):
     @defer.inlineCallbacks
-    def set_actions_for_event(self, event, user_id, profile_tag, actions):
-        actionsJson = json.dumps(actions)
-
-        ret = yield self.runInteraction(
-            "_set_actions_for_event",
-            self._simple_upsert_txn,
-            EventActionsTable.table_name,
-            {
+    def set_actions_for_event_and_users(self, event, tuples):
+        """
+        :param event: the event set actions for
+        :param tuples: list of tuples of (user_id, profile_tag, actions)
+        """
+        values = []
+        for uid, profile_tag, actions in tuples:
+            values.append({
                 'room_id': event['room_id'],
                 'event_id': event['event_id'],
-                'user_id': user_id,
-                'profile_tag': profile_tag
-            },
-            {'actions': actionsJson}
+                'user_id': uid,
+                'profile_tag': profile_tag,
+                'actions': json.dumps(actions)
+            })
+
+        yield self.runInteraction(
+            "set_actions_for_event_and_users",
+            self._simple_insert_many_txn,
+            EventActionsTable.table_name,
+            values
         )
-        defer.returnValue(ret)
 
     @defer.inlineCallbacks
     def get_unread_event_actions_by_room_for_user(