diff options
author | Erik Johnston <erik@matrix.org> | 2015-06-25 17:18:19 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-06-25 17:29:34 +0100 |
commit | 5130d80d79fe1f95ce03b8f1cfd4fbf0a32f5ac8 (patch) | |
tree | e16d302641072f6a700d3d65e919c7cb01447e47 /synapse/storage/util | |
parent | Batch SELECTs in _get_auth_chain_ids_txn (diff) | |
download | synapse-5130d80d79fe1f95ce03b8f1cfd4fbf0a32f5ac8.tar.xz |
Add bulk insert events API
Diffstat (limited to 'synapse/storage/util')
-rw-r--r-- | synapse/storage/util/id_generators.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/synapse/storage/util/id_generators.py b/synapse/storage/util/id_generators.py index 89d1643f10..83eab63098 100644 --- a/synapse/storage/util/id_generators.py +++ b/synapse/storage/util/id_generators.py @@ -108,6 +108,37 @@ class StreamIdGenerator(object): defer.returnValue(manager()) @defer.inlineCallbacks + def get_next_mult(self, store, n): + """ + Usage: + with yield stream_id_gen.get_next(store, n) as stream_ids: + # ... persist events ... + """ + if not self._current_max: + yield store.runInteraction( + "_compute_current_max", + self._get_or_compute_current_max, + ) + + with self._lock: + next_ids = range(self._current_max + 1, self._current_max + n + 1) + self._current_max += n + + for next_id in next_ids: + self._unfinished_ids.append(next_id) + + @contextlib.contextmanager + def manager(): + try: + yield next_ids + finally: + with self._lock: + for next_id in next_ids: + self._unfinished_ids.remove(next_id) + + defer.returnValue(manager()) + + @defer.inlineCallbacks def get_max_token(self, store): """Returns the maximum stream id such that all stream ids less than or equal to it have been successfully persisted. |