summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-14 14:17:36 +0100
committerErik Johnston <erik@matrix.org>2015-05-14 14:17:36 +0100
commit2f7f8e1c2b10b9444a3de7777d3bcc9d19f9d6c8 (patch)
tree4437f99cda2df7bbb78552fd0f65f78fef5cdb99 /synapse
parentloop -> gatherResults (diff)
downloadsynapse-2f7f8e1c2b10b9444a3de7777d3bcc9d19f9d6c8.tar.xz
Preemptively jump into a transaction if we ask for get_prev_content
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/_base.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 015e04a8ce..d896f5f918 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -883,20 +883,30 @@ class SQLBaseStore(object):
 
         missing_events = [e for e in event_ids if e not in event_map]
 
-        missing_events = yield self._fetch_events(
-            txn,
-            missing_events,
-            check_redacted=check_redacted,
-            get_prev_content=get_prev_content,
-            allow_rejected=allow_rejected,
-        )
+        def get_missing(txn=None):
+            missing_events = yield self._fetch_events(
+                txn,
+                missing_events,
+                check_redacted=check_redacted,
+                get_prev_content=get_prev_content,
+                allow_rejected=allow_rejected,
+            )
 
-        event_map.update(missing_events)
+            event_map.update(missing_events)
+
+            defer.returnValue([
+                event_map[e_id] for e_id in event_ids
+                if e_id in event_map and event_map[e_id]
+            ])
+
+        if missing_events and get_prev_content and not txn:
+            if get_prev_content and not txn:
+                # If we want prev_content then lets just jump into a txn.
+                res = yield self.runInteraction("_get_events", get_missing)
+                defer.returnValue(res)
+
+        defer.returnValue(get_missing())
 
-        defer.returnValue([
-            event_map[e_id] for e_id in event_ids
-            if e_id in event_map and event_map[e_id]
-        ])
 
     def _get_events_txn(self, txn, event_ids, check_redacted=True,
                         get_prev_content=False, allow_rejected=False):