Type the connection store against the config subset it uses

The store only needs user/requester/conn_id from the sync config, and is
shared between sliding sync and paginated sync (MSC4525), so type its
methods with a Protocol both configs satisfy instead of SlidingSyncConfig
(fixes the mypy failure on PaginatedSyncConfig at the
get_and_clear_connection_positions call site, and drops the now-redundant
ignore on record_new_state).
This commit is contained in:
Matthew Hodgson
2026-08-07 03:26:09 +03:00
parent b395a56a40
commit 7c9fbc49f9
2 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -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,
)
+20 -4
View File
@@ -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: