Skip to content

Commit 3e9474b

Browse files
committed
Don't use the SequenceGenerator to get the current seq value, inline the SQL
1 parent c0f9ec9 commit 3e9474b

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

synapse/storage/util/id_generators.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
from synapse.storage.engines import PostgresEngine
5656
from synapse.storage.types import Cursor
5757
from synapse.storage.util.sequence import (
58-
PostgresSequenceGenerator,
5958
build_sequence_generator,
6059
)
6160

@@ -280,7 +279,7 @@ def __init__(
280279
self._max_position_of_local_instance = self._max_seen_allocated_stream_id
281280

282281
# This goes and fills out the above state from the database.
283-
self._load_current_ids(db_conn, tables)
282+
self._load_current_ids(db_conn, tables, sequence_name)
284283

285284
self._sequence_gen = build_sequence_generator(
286285
db_conn=db_conn,
@@ -330,6 +329,7 @@ def _load_current_ids(
330329
self,
331330
db_conn: LoggingDatabaseConnection,
332331
tables: List[Tuple[str, str, str]],
332+
sequence_name: str,
333333
) -> None:
334334
cur = db_conn.cursor(txn_name="_load_current_ids")
335335

@@ -369,9 +369,12 @@ def _load_current_ids(
369369
# date. If we're using Postgres for the sequences, we can just use the current
370370
# sequence value as our own position.
371371
if self._instance_name in self._writers:
372-
if isinstance(self._sequence_gen, PostgresSequenceGenerator):
372+
if isinstance(self._db.engine, PostgresEngine):
373+
cur.execute(f"SELECT last_value FROM {sequence_name}")
374+
row = cur.fetchone()
375+
assert row is not None
373376
self._current_positions[self._instance_name] = (
374-
self._sequence_gen.current_sequence_value(cur)
377+
row[0] * self._return_factor
375378
)
376379

377380
# We set the `_persisted_upto_position` to be the minimum of all current

synapse/storage/util/sequence.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ def get_next_mult_txn(self, txn: Cursor, n: int) -> List[int]:
122122
)
123123
return [i for (i,) in txn]
124124

125-
def current_sequence_value(self, txn: Cursor) -> int:
126-
"""Load the current value of the sequence without bumping it"""
127-
txn.execute(f"SELECT last_value FROM {self._sequence_name}")
128-
row = txn.fetchone()
129-
assert row is not None
130-
return row[0]
131-
132125
def check_consistency(
133126
self,
134127
db_conn: "LoggingDatabaseConnection",

0 commit comments

Comments
 (0)