diff --git a/synapse/handlers/sliding_sync/paginated.py b/synapse/handlers/sliding_sync/paginated.py index 41ec6c11d8..b2ffb3ade7 100644 --- a/synapse/handlers/sliding_sync/paginated.py +++ b/synapse/handlers/sliding_sync/paginated.py @@ -397,7 +397,7 @@ class PaginatedSyncHandler(SlidingSyncHandler): new_connection_state.rooms.record_sent_rooms(relevant_rooms_to_send_map.keys()) connection_position = await self.connection_store.record_new_state( - sync_config=sync_config, # type: ignore[arg-type] + sync_config=sync_config, from_token=from_token, new_connection_state=new_connection_state, ) diff --git a/synapse/handlers/sliding_sync/store.py b/synapse/handlers/sliding_sync/store.py index 65febe58aa..7f27382c33 100644 --- a/synapse/handlers/sliding_sync/store.py +++ b/synapse/handlers/sliding_sync/store.py @@ -13,22 +13,38 @@ # import logging +from typing import Protocol import attr from synapse.logging.opentracing import trace from synapse.storage.databases.main import DataStore -from synapse.types import SlidingSyncStreamToken +from synapse.types import Requester, SlidingSyncStreamToken, UserID from synapse.types.handlers.sliding_sync import ( MutablePerConnectionState, PerConnectionState, - SlidingSyncConfig, ) from synapse.util.clock import Clock logger = logging.getLogger(__name__) +class SlidingSyncConnectionConfig(Protocol): + """The subset of a sync config the connection store needs: who the + connection belongs to and its client-chosen ID. Satisfied by both + `SlidingSyncConfig` and `PaginatedSyncConfig` (MSC4525), which share the + per-connection room-tracking machinery.""" + + @property + def user(self) -> UserID: ... + + @property + def requester(self) -> Requester: ... + + @property + def conn_id(self) -> str | None: ... + + @attr.s(auto_attribs=True) class SlidingSyncConnectionStore: """In-memory store of per-connection state, including what rooms we have @@ -63,7 +79,7 @@ class SlidingSyncConnectionStore: async def get_and_clear_connection_positions( self, - sync_config: SlidingSyncConfig, + sync_config: SlidingSyncConnectionConfig, from_token: SlidingSyncStreamToken | None, ) -> PerConnectionState: """Fetch the per-connection state for the token. @@ -90,7 +106,7 @@ class SlidingSyncConnectionStore: @trace async def record_new_state( self, - sync_config: SlidingSyncConfig, + sync_config: SlidingSyncConnectionConfig, from_token: SlidingSyncStreamToken | None, new_connection_state: MutablePerConnectionState, ) -> int: