From 9fdbad025f9c12e1c388d4102f95b35524a040bc Mon Sep 17 00:00:00 2001 From: Sean Quah Date: Wed, 23 Feb 2022 13:56:00 +0000 Subject: [PATCH 1/2] Minor typing fixes for `synapse/storage/persist_events.py` Signed-off-by: Sean Quah --- changelog.d/12069.misc | 1 + synapse/storage/persist_events.py | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 changelog.d/12069.misc diff --git a/changelog.d/12069.misc b/changelog.d/12069.misc new file mode 100644 index 000000000000..8374a63220d1 --- /dev/null +++ b/changelog.d/12069.misc @@ -0,0 +1 @@ +Minor typing fixes. diff --git a/synapse/storage/persist_events.py b/synapse/storage/persist_events.py index 428d66a617b1..f68ec3331658 100644 --- a/synapse/storage/persist_events.py +++ b/synapse/storage/persist_events.py @@ -460,14 +460,13 @@ async def _persist_event_batch( ) for room_id, ev_ctx_rm in events_by_room.items(): - latest_event_ids = ( + latest_event_ids = set( await self.main_store.get_latest_event_ids_in_room(room_id) ) new_latest_event_ids = await self._calculate_new_extremities( room_id, ev_ctx_rm, latest_event_ids ) - latest_event_ids = set(latest_event_ids) if new_latest_event_ids == latest_event_ids: # No change in extremities, so no change in state continue @@ -567,7 +566,7 @@ async def _persist_event_batch( ) if not is_still_joined: logger.info("Server no longer in room %s", room_id) - latest_event_ids = [] + latest_event_ids = set() current_state = {} delta.no_longer_in_room = True @@ -906,9 +905,9 @@ async def _prune_extremities( # Ideally we'd figure out a way of still being able to drop old # dummy events that reference local events, but this is good enough # as a first cut. - events_to_check = [event] + events_to_check: Collection[EventBase] = [event] while events_to_check: - new_events = set() + new_events: Set[str] = set() for event_to_check in events_to_check: if self.is_mine_id(event_to_check.sender): if event_to_check.type != EventTypes.Dummy: From 0f259162ccc4f5bba4647fb1213fdd72e2ecf830 Mon Sep 17 00:00:00 2001 From: Sean Quah Date: Wed, 23 Feb 2022 13:56:32 +0000 Subject: [PATCH 2/2] Ensure that `get_datastores().main` is typed Signed-off-by: Sean Quah --- changelog.d/12070.misc | 1 + synapse/storage/databases/__init__.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelog.d/12070.misc diff --git a/changelog.d/12070.misc b/changelog.d/12070.misc new file mode 100644 index 000000000000..d4bedc6b97cb --- /dev/null +++ b/changelog.d/12070.misc @@ -0,0 +1 @@ +Remove legacy `HomeServer.get_datastore()`. diff --git a/synapse/storage/databases/__init__.py b/synapse/storage/databases/__init__.py index cfe887b7f73d..ce3d1d4e942e 100644 --- a/synapse/storage/databases/__init__.py +++ b/synapse/storage/databases/__init__.py @@ -24,6 +24,7 @@ if TYPE_CHECKING: from synapse.server import HomeServer + from synapse.storage.databases.main import DataStore logger = logging.getLogger(__name__) @@ -44,7 +45,7 @@ class Databases(Generic[DataStoreT]): """ databases: List[DatabasePool] - main: DataStoreT + main: "DataStore" # FIXME: #11165: actually an instance of `main_store_class` state: StateGroupDataStore persist_events: Optional[PersistEventsStore]