summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorDavid Baker <dbkr@users.noreply.github.com>2016-01-22 15:25:52 +0000
committerDavid Baker <dbkr@users.noreply.github.com>2016-01-22 15:25:52 +0000
commit74f49f99f9d82f749897ca52b1fd92fe634476c5 (patch)
tree39227aed811880ffbcd5a23c07a08b1f8edead22 /synapse/storage
parentMerge pull request #519 from matrix-org/dbkr/treecache (diff)
parentDon't crash if a user has no push rule enabled entries (diff)
downloadsynapse-74f49f99f9d82f749897ca52b1fd92fe634476c5.tar.xz
Merge pull request #520 from matrix-org/dbkr/bulk_push_overlay_enabled
Overlay the push_rules_enabled map for users
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/push_rule.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py
index 2adfefd994..35ec7e8cef 100644
--- a/synapse/storage/push_rule.py
+++ b/synapse/storage/push_rule.py
@@ -94,6 +94,35 @@ class PushRuleStore(SQLBaseStore):
         defer.returnValue(results)
 
     @defer.inlineCallbacks
+    def bulk_get_push_rules_enabled(self, user_ids):
+        if not user_ids:
+            defer.returnValue({})
+
+        batch_size = 100
+
+        def f(txn, user_ids_to_fetch):
+            sql = (
+                "SELECT user_name, rule_id, enabled"
+                " FROM push_rules_enable"
+                " WHERE user_name"
+                " IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")"
+            )
+            txn.execute(sql, user_ids_to_fetch)
+            return self.cursor_to_dict(txn)
+
+        results = {}
+
+        chunks = [user_ids[i:i+batch_size] for i in xrange(0, len(user_ids), batch_size)]
+        for batch_user_ids in chunks:
+            rows = yield self.runInteraction(
+                "bulk_get_push_rules_enabled", f, batch_user_ids
+            )
+
+            for row in rows:
+                results.setdefault(row['user_name'], {})[row['rule_id']] = row['enabled']
+        defer.returnValue(results)
+
+    @defer.inlineCallbacks
     def add_push_rule(self, before, after, **kwargs):
         vals = kwargs
         if 'conditions' in vals: