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 b2cd3b8
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from synapse.storage.engines import PostgresEngine
from synapse.storage.util.id_generators import (
AbstractStreamIdGenerator,
AbstractStreamIdTracker,
MultiWriterIdGenerator,
StreamIdGenerator,
)
Expand All @@ -63,14 +62,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 +472,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 +510,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 +585,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 +690,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 b2cd3b8

Please sign in to comment.