summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/event_push_actions.py30
-rw-r--r--synapse/storage/schema/delta/35/event_push_actions_index.sql17
2 files changed, 47 insertions, 0 deletions
diff --git a/synapse/storage/event_push_actions.py b/synapse/storage/event_push_actions.py
index 10e9305f7b..8632b2f936 100644
--- a/synapse/storage/event_push_actions.py
+++ b/synapse/storage/event_push_actions.py
@@ -17,6 +17,7 @@ from ._base import SQLBaseStore
 from twisted.internet import defer
 from synapse.util.caches.descriptors import cachedInlineCallbacks
 from synapse.types import RoomStreamToken
+from synapse.storage.engines import PostgresEngine
 from .stream import lower_bound
 
 import logging
@@ -26,10 +27,17 @@ logger = logging.getLogger(__name__)
 
 
 class EventPushActionsStore(SQLBaseStore):
+    EPA_HIGHLIGHT_INDEX = "epa_highlight_index"
+
     def __init__(self, hs):
         self.stream_ordering_month_ago = None
         super(EventPushActionsStore, self).__init__(hs)
 
+        self.register_background_update_handler(
+            self.EPA_HIGHLIGHT_INDEX,
+            self._background_index_epa_highlight,
+        )
+
     def _set_push_actions_for_event_and_users_txn(self, txn, event, tuples):
         """
         Args:
@@ -498,6 +506,28 @@ class EventPushActionsStore(SQLBaseStore):
 
         return range_end
 
+    @defer.inlineCallbacks
+    def _background_index_epa_highlight(self, progress, batch_size):
+        def reindex_txn(txn):
+            if isinstance(self.database_engine, PostgresEngine):
+                txn.execute(
+                    "CREATE INDEX CONCURRENTLY event_push_actions_u_highlight"
+                    " on event_push_actions(user_id, highlight, stream_ordering)"
+                )
+            else:
+                txn.execute(
+                    "CREATE INDEX event_push_actions_u_highlight"
+                    " on event_push_actions(user_id, highlight, stream_ordering)"
+                )
+
+        yield self.runInteraction(
+            self.EPA_HIGHLIGHT_INDEX, reindex_txn
+        )
+
+        yield self._end_background_update(self.EPA_HIGHLIGHT_INDEX)
+
+        defer.returnValue(1)
+
 
 def _action_has_highlight(actions):
     for action in actions:
diff --git a/synapse/storage/schema/delta/35/event_push_actions_index.sql b/synapse/storage/schema/delta/35/event_push_actions_index.sql
new file mode 100644
index 0000000000..2e836d8e9c
--- /dev/null
+++ b/synapse/storage/schema/delta/35/event_push_actions_index.sql
@@ -0,0 +1,17 @@
+/* Copyright 2016 OpenMarket Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ INSERT into background_updates (update_name, progress_json)
+     VALUES ('epa_highlight_index', '{}');