summary refs log tree commit diff
path: root/synapse/storage/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-01-21 17:00:12 +0000
committerGitHub <noreply@github.com>2021-01-21 17:00:12 +0000
commit758ed5f1bc16f4b73d73d94129761a8680fd71c5 (patch)
tree7d6b771d5ff3f8368faf6f4a4c44a5706c9ae7c4 /synapse/storage/util
parentIncrease perf of handling concurrent use of StreamIDGenerators. (#9190) (diff)
downloadsynapse-758ed5f1bc16f4b73d73d94129761a8680fd71c5.tar.xz
Speed up chain cover calculation (#9176)
Diffstat (limited to 'synapse/storage/util')
-rw-r--r--synapse/storage/util/sequence.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/synapse/storage/util/sequence.py b/synapse/storage/util/sequence.py
index c780ade077..0ec4dc2918 100644
--- a/synapse/storage/util/sequence.py
+++ b/synapse/storage/util/sequence.py
@@ -70,6 +70,11 @@ class SequenceGenerator(metaclass=abc.ABCMeta):
         ...
 
     @abc.abstractmethod
+    def get_next_mult_txn(self, txn: Cursor, n: int) -> List[int]:
+        """Get the next `n` IDs in the sequence"""
+        ...
+
+    @abc.abstractmethod
     def check_consistency(
         self,
         db_conn: "LoggingDatabaseConnection",
@@ -219,6 +224,17 @@ class LocalSequenceGenerator(SequenceGenerator):
             self._current_max_id += 1
             return self._current_max_id
 
+    def get_next_mult_txn(self, txn: Cursor, n: int) -> List[int]:
+        with self._lock:
+            if self._current_max_id is None:
+                assert self._callback is not None
+                self._current_max_id = self._callback(txn)
+                self._callback = None
+
+            first_id = self._current_max_id + 1
+            self._current_max_id += n
+            return [first_id + i for i in range(n)]
+
     def check_consistency(
         self,
         db_conn: Connection,