summary refs log tree commit diff
path: root/synapse/storage/search.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-11-10 15:50:58 +0000
committerMark Haines <mark.haines@matrix.org>2015-11-10 15:50:58 +0000
commita412b9a465cb6a64f44e3656d8645977f43c275f (patch)
tree7b749e92ec5972fc0d1e300b678e755f5829734c /synapse/storage/search.py
parentAdd background update task for reindexing event search (diff)
downloadsynapse-a412b9a465cb6a64f44e3656d8645977f43c275f.tar.xz
Run the background updates when starting synapse.
Diffstat (limited to 'synapse/storage/search.py')
-rw-r--r--synapse/storage/search.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/storage/search.py b/synapse/storage/search.py
index f7c269865d..d170c546b5 100644
--- a/synapse/storage/search.py
+++ b/synapse/storage/search.py
@@ -29,6 +29,11 @@ class SearchStore(BackgroundUpdateStore):
 
     EVENT_SEARCH_UPDATE_NAME = "event_search"
 
+    def __init__(self, hs):
+        super(SearchStore, self).__init__(hs)
+        self.register_background_update_handler(
+            self.EVENT_SEARCH_UPDATE_NAME, self._background_reindex_search
+        )
 
     @defer.inlineCallbacks
     def _background_reindex_search(self, progress, batch_size):
@@ -74,7 +79,7 @@ class SearchStore(BackgroundUpdateStore):
                     elif event.type == "m.room.name":
                         key = "content.name"
                         value = content["name"]
-                except Exception:
+                except (KeyError, AttributeError):
                     # If the event is missing a necessary field then
                     # skip over it.
                     continue
@@ -96,7 +101,7 @@ class SearchStore(BackgroundUpdateStore):
                 raise Exception("Unrecognized database engine")
 
             for index in range(0, len(event_search_rows), INSERT_CLUMP_SIZE):
-                clump = event_search_rows[index : index + INSERT_CLUMP_SIZE)
+                clump = event_search_rows[index:index + INSERT_CLUMP_SIZE]
                 txn.execute_many(sql, clump)
 
             progress = {
@@ -116,7 +121,7 @@ class SearchStore(BackgroundUpdateStore):
         )
 
         if result is None:
-            yield _end_background_update(self.EVENT_SEARCH_UPDATE_NAME)
+            yield self._end_background_update(self.EVENT_SEARCH_UPDATE_NAME)
 
         defer.returnValue(result)