summary refs log tree commit diff
path: root/synapse/storage/events.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-15 11:35:04 +0100
committerErik Johnston <erik@matrix.org>2015-05-15 11:35:04 +0100
commitaa32bd38e40cd8d69406fe74581290ad7fe34f35 (patch)
treef0e2e83189ae3f4f63a5c70656b7877089966da9 /synapse/storage/events.py
parentSrsly. Don't use closures. Baaaaaad (diff)
downloadsynapse-aa32bd38e40cd8d69406fe74581290ad7fe34f35.tar.xz
Add a wait
Diffstat (limited to 'synapse/storage/events.py')
-rw-r--r--synapse/storage/events.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 2c3e6d5a5c..f694b877f4 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -502,6 +502,7 @@ class EventsStore(SQLBaseStore):
 
     def _do_fetch(self, conn):
         event_list = []
+        i = 0
         while True:
             try:
                 logger.debug("do_fetch getting lock")
@@ -510,8 +511,14 @@ class EventsStore(SQLBaseStore):
                     event_list = self._event_fetch_list
                     self._event_fetch_list = []
                     if not event_list:
-                        self._event_fetch_ongoing -= 1
-                        return
+                        if self.database_engine.single_threaded or i > 5:
+                            self._event_fetch_ongoing -= 1
+                            return
+                        else:
+                            self._event_fetch_lock.wait(0.1)
+                            i += 1
+                            continue
+                    i = 0
 
                 event_id_lists = zip(*event_list)[0]
                 event_ids = [
@@ -566,6 +573,8 @@ class EventsStore(SQLBaseStore):
                 (events, events_d)
             )
 
+            self._event_fetch_lock.notify_all()
+
             if self._event_fetch_ongoing < 1:
                 self._event_fetch_ongoing += 1
                 should_start = True