Also use stable name in SendJoinResponse struct (#14841)

* Also use stable name in SendJoinResponse struct

follow-up to #14832

* Changelog

* Fix a rename I missed

* Run black

* Update synapse/federation/federation_client.py

Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>

Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
This commit is contained in:
David Robertson 2023-01-16 12:40:25 +00:00 committed by GitHub
parent 5f171c1651
commit 85a7a201fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 14 deletions

1
changelog.d/14841.misc Normal file
View file

@ -0,0 +1 @@
Faster joins: use stable identifiers from [MSC3706](https://github.com/matrix-org/matrix-spec-proposals/pull/3706).

View file

@ -1142,9 +1142,9 @@ class FederationClient(FederationBase):
% (auth_chain_create_events,) % (auth_chain_create_events,)
) )
if response.partial_state and not response.servers_in_room: if response.members_omitted and not response.servers_in_room:
raise InvalidResponseError( raise InvalidResponseError(
"partial_state was set, but no servers were listed in the room" "members_omitted was set, but no servers were listed in the room"
) )
return SendJoinResult( return SendJoinResult(
@ -1152,7 +1152,7 @@ class FederationClient(FederationBase):
state=signed_state, state=signed_state,
auth_chain=signed_auth, auth_chain=signed_auth,
origin=destination, origin=destination,
partial_state=response.partial_state, partial_state=response.members_omitted,
servers_in_room=response.servers_in_room or [], servers_in_room=response.servers_in_room or [],
) )

View file

@ -1502,7 +1502,7 @@ def _get_event_ids_for_partial_state_join(
prev_state_ids: StateMap[str], prev_state_ids: StateMap[str],
summary: Dict[str, MemberSummary], summary: Dict[str, MemberSummary],
) -> Collection[str]: ) -> Collection[str]:
"""Calculate state to be retuned in a partial_state send_join """Calculate state to be returned in a partial_state send_join
Args: Args:
join_event: the join event being send_joined join_event: the join event being send_joined

View file

@ -795,7 +795,7 @@ class SendJoinResponse:
event: Optional[EventBase] = None event: Optional[EventBase] = None
# The room state is incomplete # The room state is incomplete
partial_state: bool = False members_omitted: bool = False
# List of servers in the room # List of servers in the room
servers_in_room: Optional[List[str]] = None servers_in_room: Optional[List[str]] = None
@ -835,16 +835,18 @@ def _event_list_parser(
@ijson.coroutine @ijson.coroutine
def _partial_state_parser(response: SendJoinResponse) -> Generator[None, Any, None]: def _members_omitted_parser(response: SendJoinResponse) -> Generator[None, Any, None]:
"""Helper function for use with `ijson.items_coro` """Helper function for use with `ijson.items_coro`
Parses the partial_state field in send_join responses Parses the members_omitted field in send_join responses
""" """
while True: while True:
val = yield val = yield
if not isinstance(val, bool): if not isinstance(val, bool):
raise TypeError("partial_state must be a boolean") raise TypeError(
response.partial_state = val "members_omitted (formerly org.matrix.msc370c.partial_state) must be a boolean"
)
response.members_omitted = val
@ijson.coroutine @ijson.coroutine
@ -905,7 +907,7 @@ class SendJoinParser(ByteParser[SendJoinResponse]):
if not v1_api: if not v1_api:
self._coros.append( self._coros.append(
ijson.items_coro( ijson.items_coro(
_partial_state_parser(self._response), _members_omitted_parser(self._response),
"org.matrix.msc3706.partial_state", "org.matrix.msc3706.partial_state",
use_float="True", use_float="True",
) )
@ -913,7 +915,7 @@ class SendJoinParser(ByteParser[SendJoinResponse]):
# The stable field name comes last, so it "wins" if the fields disagree # The stable field name comes last, so it "wins" if the fields disagree
self._coros.append( self._coros.append(
ijson.items_coro( ijson.items_coro(
_partial_state_parser(self._response), _members_omitted_parser(self._response),
"members_omitted", "members_omitted",
use_float="True", use_float="True",
) )

View file

@ -68,11 +68,11 @@ class SendJoinParserTestCase(TestCase):
self.assertEqual(len(parsed_response.state), 1, parsed_response) self.assertEqual(len(parsed_response.state), 1, parsed_response)
self.assertEqual(parsed_response.event_dict, {}, parsed_response) self.assertEqual(parsed_response.event_dict, {}, parsed_response)
self.assertIsNone(parsed_response.event, parsed_response) self.assertIsNone(parsed_response.event, parsed_response)
self.assertFalse(parsed_response.partial_state, parsed_response) self.assertFalse(parsed_response.members_omitted, parsed_response)
self.assertEqual(parsed_response.servers_in_room, None, parsed_response) self.assertEqual(parsed_response.servers_in_room, None, parsed_response)
def test_partial_state(self) -> None: def test_partial_state(self) -> None:
"""Check that the partial_state flag is correctly parsed""" """Check that the members_omitted flag is correctly parsed"""
def parse(response: JsonDict) -> bool: def parse(response: JsonDict) -> bool:
parser = SendJoinParser(RoomVersions.V1, False) parser = SendJoinParser(RoomVersions.V1, False)
@ -83,7 +83,7 @@ class SendJoinParserTestCase(TestCase):
# Retrieve and check the parsed SendJoinResponse # Retrieve and check the parsed SendJoinResponse
parsed_response = parser.finish() parsed_response = parser.finish()
return parsed_response.partial_state return parsed_response.members_omitted
self.assertTrue(parse({"members_omitted": True})) self.assertTrue(parse({"members_omitted": True}))
self.assertTrue(parse({"org.matrix.msc3706.partial_state": True})) self.assertTrue(parse({"org.matrix.msc3706.partial_state": True}))