Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Make _account_data_id_gen always an AbstractStreamIdGenerator to appe…
Browse files Browse the repository at this point in the history
…ase mypy

As get_next_txn is part of AbstractStreamIdGenerator, not
AbstractStreamIdTracker. I'm not sure why we insisted in trying to type
it as a Tracker vs. a Generator, and then checking that elsewhere in the
codebase. The init function of AccountDataWorkerStore will always create
_account_data_id_gen as either a StreamIdGenerator or a
MultiWriterIdGenerator. Both of which are AbstractStreamidGenerators.
  • Loading branch information
anoadragon453 committed Mar 2, 2023
1 parent ae14dfc commit 07aaeef
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ def __init__(
):
super().__init__(database, db_conn, hs)

# `_can_write_to_account_data` indicates whether the current worker is allowed
# to write account data. A value of `True` implies that `_account_data_id_gen`
# is an `AbstractStreamIdGenerator` and not just a tracker.
self._account_data_id_gen: AbstractStreamIdTracker
self._can_write_to_account_data = (
self._instance_name in hs.config.worker.writers.account_data
)

self._account_data_id_gen: AbstractStreamIdGenerator

if isinstance(database.engine, PostgresEngine):
self._account_data_id_gen = MultiWriterIdGenerator(
db_conn=db_conn,
Expand Down Expand Up @@ -475,7 +473,6 @@ async def add_account_data_to_room(
The maximum stream ID.
"""
assert self._can_write_to_account_data
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)

content_json = json_encoder.encode(content)

Expand Down Expand Up @@ -514,7 +511,6 @@ async def remove_account_data_for_room(
The maximum account data stream position.
"""
assert self._can_write_to_account_data
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)

def _remove_account_data_for_room_txn(txn: LoggingTransaction) -> Optional[int]:
"""
Expand Down Expand Up @@ -590,7 +586,6 @@ async def add_account_data_for_user(
The maximum stream ID.
"""
assert self._can_write_to_account_data
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)

async with self._account_data_id_gen.get_next() as next_id:
await self.db_pool.runInteraction(
Expand Down Expand Up @@ -696,7 +691,6 @@ async def remove_account_data_for_user(
The maximum account data stream position.
"""
assert self._can_write_to_account_data
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)

def _remove_account_data_for_user_txn(txn: LoggingTransaction) -> Optional[int]:
"""
Expand Down

0 comments on commit 07aaeef

Please sign in to comment.