summary refs log tree commit diff
path: root/synapse/storage/transactions.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-05-06 11:30:55 +0100
committerErik Johnston <erik@matrix.org>2016-05-06 11:30:55 +0100
commitd13459636fab9637a43c950d17f883ca77b832f7 (patch)
tree043568db04806d490425e04b1c3c97dc8e707d00 /synapse/storage/transactions.py
parentDon't needlessly enter transaction (diff)
downloadsynapse-d13459636fab9637a43c950d17f883ca77b832f7.tar.xz
Pull prev txn from in memory
Diffstat (limited to '')
-rw-r--r--synapse/storage/transactions.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/synapse/storage/transactions.py b/synapse/storage/transactions.py
index ba1969b243..6c7481a728 100644
--- a/synapse/storage/transactions.py
+++ b/synapse/storage/transactions.py
@@ -58,6 +58,8 @@ class TransactionStore(SQLBaseStore):
         # Newly delivered transactions that *were* persisted while in flight
         self.update_delivered_transactions = {}
 
+        self.last_transaction = {}
+
         reactor.addSystemEventTrigger("before", "shutdown", self._persist_in_mem_txns)
         hs.get_clock().looping_call(
             self._persist_in_mem_txns,
@@ -159,11 +161,15 @@ class TransactionStore(SQLBaseStore):
 
         self.inflight_transactions.setdefault(destination, {})[transaction_id] = txn_row
 
-        return self.runInteraction(
-            "_get_prevs_txn",
-            self._get_prevs_txn,
-            destination,
-        )
+        prev_txn = self.last_transaction.get(destination)
+        if prev_txn:
+            return defer.succeed(prev_txn)
+        else:
+            return self.runInteraction(
+                "_get_prevs_txn",
+                self._get_prevs_txn,
+                destination,
+            )
 
     def _get_prevs_txn(self, txn, destination):
         # First we find out what the prev_txns should be.
@@ -196,6 +202,8 @@ class TransactionStore(SQLBaseStore):
             destination, {}
         ).pop(transaction_id, None)
 
+        self.last_transaction[destination] = transaction_id
+
         if txn_row:
             d = self.new_delivered_transactions.setdefault(destination, {})
             d[transaction_id] = txn_row._replace(