diff --git a/synapse/handlers/sliding_sync/paginated.py b/synapse/handlers/sliding_sync/paginated.py index cb58c8e7eb..7bddfaf1c4 100644 --- a/synapse/handlers/sliding_sync/paginated.py +++ b/synapse/handlers/sliding_sync/paginated.py @@ -38,8 +38,8 @@ from synapse.handlers.sliding_sync.extensions import SlidingSyncExtensionHandler from synapse.logging.opentracing import log_kv, set_tag, start_active_span, trace from synapse.types import Requester, SlidingSyncStreamToken, StrCollection, StreamToken from synapse.types.handlers.paginated_sync import ( - PaginatedSyncConfig, - PaginatedSyncResult, + MSC4525PaginatedSyncConfig, + MSC4525PaginatedSyncResult, ) from synapse.types.handlers.sliding_sync import ( HaveSentRoomFlag, @@ -63,7 +63,7 @@ logger = logging.getLogger(__name__) AGING_LANE_FRACTION = 4 -class PaginatedSyncExtensionHandler(SlidingSyncExtensionHandler): +class MSC4525PaginatedSyncExtensionHandler(SlidingSyncExtensionHandler): """The sliding sync extensions without the `lists`/`rooms` scoping: with no lists and no subscriptions there is nothing to scope, so an enabled extension simply applies to the rooms in the response.""" @@ -78,7 +78,7 @@ class PaginatedSyncExtensionHandler(SlidingSyncExtensionHandler): return set(actual_room_ids) -class PaginatedSyncHandler(SlidingSyncHandler): +class MSC4525PaginatedSyncHandler(SlidingSyncHandler): def __init__(self, hs: "HomeServer"): super().__init__(hs) @@ -91,22 +91,22 @@ class PaginatedSyncHandler(SlidingSyncHandler): self.track_room_configs = False # Extensions lose their scoping fields. - self.extensions = PaginatedSyncExtensionHandler(hs) + self.extensions = MSC4525PaginatedSyncExtensionHandler(hs) async def wait_for_paginated_sync_for_user( self, requester: Requester, - sync_config: PaginatedSyncConfig, + sync_config: MSC4525PaginatedSyncConfig, from_token: SlidingSyncStreamToken | None = None, timeout_ms: int = 0, - ) -> tuple[PaginatedSyncResult, bool]: + ) -> tuple[MSC4525PaginatedSyncResult, bool]: """ Get the paginated sync for a client if we have new data for it now, otherwise wait for new data to arrive on the server (mirrors `SlidingSyncHandler.wait_for_sync_for_user`). Returns: - The `PaginatedSyncResult` and whether we waited for new activity + The `MSC4525PaginatedSyncResult` and whether we waited for new activity before responding. """ did_wait = False @@ -127,7 +127,7 @@ class PaginatedSyncHandler(SlidingSyncHandler): logger.warning( "Timed out waiting for worker to catch up. Returning empty response" ) - return PaginatedSyncResult.empty(from_token), did_wait + return MSC4525PaginatedSyncResult.empty(from_token), did_wait after_wait_ts = self.clock.time_msec() if after_wait_ts - before_wait_ts > 1_000: @@ -149,7 +149,7 @@ class PaginatedSyncHandler(SlidingSyncHandler): async def current_sync_callback( before_token: StreamToken, after_token: StreamToken - ) -> PaginatedSyncResult: + ) -> MSC4525PaginatedSyncResult: return await self.current_paginated_sync_for_user( sync_config, from_token=from_token, @@ -169,10 +169,10 @@ class PaginatedSyncHandler(SlidingSyncHandler): @trace async def current_paginated_sync_for_user( self, - sync_config: PaginatedSyncConfig, + sync_config: MSC4525PaginatedSyncConfig, to_token: StreamToken, from_token: SlidingSyncStreamToken | None = None, - ) -> PaginatedSyncResult: + ) -> MSC4525PaginatedSyncResult: """ Generate a paginated sync response for the token range (> `from_token` and <= `to_token`). @@ -364,9 +364,9 @@ class PaginatedSyncHandler(SlidingSyncHandler): assert room_status.last_token is not None return room_status.last_token.stream - aged_room_ids = sorted( - previously_room_ids, key=last_sent_stream_pos - )[:aging_lane_size] + aged_room_ids = sorted(previously_room_ids, key=last_sent_stream_pos)[ + :aging_lane_size + ] sorted_room_infos = await self.room_lists.sort_rooms( {room_id: sync_room_map[room_id] for room_id in candidates}, @@ -461,7 +461,7 @@ class PaginatedSyncHandler(SlidingSyncHandler): new_connection_state=new_connection_state, ) - result = PaginatedSyncResult( + result = MSC4525PaginatedSyncResult( next_pos=SlidingSyncStreamToken(to_token, connection_position), rooms=rooms, extensions=extensions, diff --git a/synapse/handlers/sliding_sync/store.py b/synapse/handlers/sliding_sync/store.py index 7f27382c33..599784f4d8 100644 --- a/synapse/handlers/sliding_sync/store.py +++ b/synapse/handlers/sliding_sync/store.py @@ -32,7 +32,7 @@ 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 + `SlidingSyncConfig` and `MSC4525PaginatedSyncConfig` (MSC4525), which share the per-connection room-tracking machinery.""" @property diff --git a/synapse/rest/client/paginated_sync.py b/synapse/rest/client/paginated_sync.py index 1f403e36f2..6ce02a8693 100644 --- a/synapse/rest/client/paginated_sync.py +++ b/synapse/rest/client/paginated_sync.py @@ -36,10 +36,10 @@ from synapse.rest.client._base import client_patterns from synapse.rest.client.sync import SlidingSyncRestServlet from synapse.types import JsonDict, Requester, SlidingSyncStreamToken from synapse.types.handlers.paginated_sync import ( - PaginatedSyncConfig, - PaginatedSyncResult, + MSC4525PaginatedSyncConfig, + MSC4525PaginatedSyncResult, ) -from synapse.types.rest.client import PaginatedSyncBody +from synapse.types.rest.client import MSC4525PaginatedSyncBody if TYPE_CHECKING: from synapse.server import HomeServer @@ -47,7 +47,7 @@ if TYPE_CHECKING: logger = logging.getLogger(__name__) -class PaginatedSyncRestServlet(SlidingSyncRestServlet): +class MSC4525PaginatedSyncRestServlet(SlidingSyncRestServlet): """ API endpoint for MSC4525 Paginated Sync. `POST` with a JSON body of `page_size`/`limit`/`history`/`required_state`/`extensions`; responds with @@ -84,7 +84,9 @@ class PaginatedSyncRestServlet(SlidingSyncRestServlet): self.store, from_token_string ) - body = parse_and_validate_json_object_from_request(request, PaginatedSyncBody) + body = parse_and_validate_json_object_from_request( + request, MSC4525PaginatedSyncBody + ) set_tag( "paginated_sync.sync_type", @@ -99,7 +101,7 @@ class PaginatedSyncRestServlet(SlidingSyncRestServlet): } ) - sync_config = PaginatedSyncConfig( + sync_config = MSC4525PaginatedSyncConfig( user=user, requester=requester, # Namespace the connection ID so a paginated sync connection @@ -142,7 +144,7 @@ class PaginatedSyncRestServlet(SlidingSyncRestServlet): async def encode_paginated_response( self, requester: Requester, - result: PaginatedSyncResult, + result: MSC4525PaginatedSyncResult, ) -> JsonDict: response: JsonDict = {} @@ -167,4 +169,4 @@ class PaginatedSyncRestServlet(SlidingSyncRestServlet): def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: # Always registered; access is gated per user (or globally) via # `ExperimentalFeature.MSC4525` in `on_POST`. - PaginatedSyncRestServlet(hs).register(http_server) + MSC4525PaginatedSyncRestServlet(hs).register(http_server) diff --git a/synapse/server.py b/synapse/server.py index 15ef7fcf8a..df4c398a2d 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -131,7 +131,7 @@ from synapse.handlers.search import SearchHandler from synapse.handlers.send_email import SendEmailHandler from synapse.handlers.set_password import SetPasswordHandler from synapse.handlers.sliding_sync import SlidingSyncHandler -from synapse.handlers.sliding_sync.paginated import PaginatedSyncHandler +from synapse.handlers.sliding_sync.paginated import MSC4525PaginatedSyncHandler from synapse.handlers.sso import SsoHandler from synapse.handlers.stats import StatsHandler from synapse.handlers.sync import SyncHandler @@ -861,8 +861,8 @@ class HomeServer(metaclass=abc.ABCMeta): return SlidingSyncHandler(self) @cache_in_self - def get_paginated_sync_handler(self) -> PaginatedSyncHandler: - return PaginatedSyncHandler(self) + def get_paginated_sync_handler(self) -> MSC4525PaginatedSyncHandler: + return MSC4525PaginatedSyncHandler(self) @cache_in_self def get_room_list_handler(self) -> RoomListHandler: diff --git a/synapse/types/handlers/paginated_sync.py b/synapse/types/handlers/paginated_sync.py index 95a712d826..e14f61d81c 100644 --- a/synapse/types/handlers/paginated_sync.py +++ b/synapse/types/handlers/paginated_sync.py @@ -25,12 +25,12 @@ from pydantic import ConfigDict from synapse.types import Requester, SlidingSyncStreamToken, UserID from synapse.types.handlers.sliding_sync import SlidingSyncResult -from synapse.types.rest.client import PaginatedSyncBody +from synapse.types.rest.client import MSC4525PaginatedSyncBody -class PaginatedSyncConfig(PaginatedSyncBody): +class MSC4525PaginatedSyncConfig(MSC4525PaginatedSyncBody): """ - Inherit from `PaginatedSyncBody` since we need all of the same fields and add a few + Inherit from `MSC4525PaginatedSyncBody` since we need all of the same fields and add a few extra fields that we need in the handler """ @@ -52,7 +52,7 @@ class PaginatedSyncConfig(PaginatedSyncBody): @attr.s(slots=True, frozen=True, auto_attribs=True) -class PaginatedSyncResult: +class MSC4525PaginatedSyncResult: """ The response body for a paginated sync request. @@ -85,9 +85,9 @@ class PaginatedSyncResult: return bool(self.rooms or self.extensions or self.pending) @staticmethod - def empty(next_pos: SlidingSyncStreamToken) -> "PaginatedSyncResult": + def empty(next_pos: SlidingSyncStreamToken) -> "MSC4525PaginatedSyncResult": "Return a new empty result" - return PaginatedSyncResult( + return MSC4525PaginatedSyncResult( next_pos=next_pos, rooms={}, extensions=SlidingSyncResult.Extensions(), diff --git a/synapse/types/rest/client/__init__.py b/synapse/types/rest/client/__init__.py index 6d54aeea02..8acd013f16 100644 --- a/synapse/types/rest/client/__init__.py +++ b/synapse/types/rest/client/__init__.py @@ -511,7 +511,7 @@ class SlidingSyncBody(RequestBodyModel): return value -class PaginatedSyncBody(RequestBodyModel): +class MSC4525PaginatedSyncBody(RequestBodyModel): """ Paginated Sync API request body (MSC4525, a dialect of MSC4186 without lists/ranges/subscriptions). diff --git a/tests/rest/client/sliding_sync/test_msc4525_paginated_sync.py b/tests/rest/client/sliding_sync/test_msc4525_paginated_sync.py index a7f6cfa3cf..d4161306f5 100644 --- a/tests/rest/client/sliding_sync/test_msc4525_paginated_sync.py +++ b/tests/rest/client/sliding_sync/test_msc4525_paginated_sync.py @@ -38,7 +38,7 @@ from tests import unittest logger = logging.getLogger(__name__) -class PaginatedSyncTestCase(unittest.HomeserverTestCase): +class MSC4525PaginatedSyncTestCase(unittest.HomeserverTestCase): """ Tests for `POST /_matrix/client/unstable/org.matrix.msc4525/sync`: paging on initial sync, per-room gapping on incremental sync, backlog @@ -440,7 +440,7 @@ class PaginatedSyncTestCase(unittest.HomeserverTestCase): self.assertIn(room_id, account_data_response, response) -class PaginatedSyncPerUserEnablementTestCase(unittest.HomeserverTestCase): +class MSC4525PaginatedSyncPerUserEnablementTestCase(unittest.HomeserverTestCase): """The endpoint is disabled by default and enablable per user via the admin experimental-features API (`ExperimentalFeature.MSC4525`)."""