summary refs log tree commit diff
path: root/synapse/storage/stream.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-20 16:23:01 +0000
committerErik Johnston <erik@matrix.org>2015-03-20 16:23:01 +0000
commit4848fdbf59b7e4c28baf86179cfd753e433f4d3f (patch)
tree91c2bd508fde6087bad90ce3c79be3f20b40d21e /synapse/storage/stream.py
parentAdd the tiniest of tiny one-element caches to get_room_events_max_id() as it'... (diff)
parentPEP8 (diff)
downloadsynapse-4848fdbf59b7e4c28baf86179cfd753e433f4d3f.tar.xz
Merge pull request #113 from matrix-org/store_rearrangement
Store rearrangement
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index 850ab9e0e3..66f307e640 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -420,6 +420,25 @@ class StreamStore(SQLBaseStore):
             self._get_room_events_max_id_txn
         )
 
+    @defer.inlineCallbacks
+    def _get_min_token(self):
+        row = yield self._execute(
+            "_get_min_token", None, "SELECT MIN(stream_ordering) FROM events"
+        )
+
+        self.min_token = row[0][0] if row and row[0] and row[0][0] else -1
+        self.min_token = min(self.min_token, -1)
+
+        logger.debug("min_token is: %s", self.min_token)
+
+        defer.returnValue(self.min_token)
+
+    def get_next_stream_id(self):
+        with self._next_stream_id_lock:
+            i = self._next_stream_id
+            self._next_stream_id += 1
+            return i
+
     def _get_room_events_max_id_txn(self, txn):
         txn.execute(
             "SELECT MAX(stream_ordering) as m FROM events"