Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add parameter to control whether we do a faster join #14843

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14843.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a parameter to control whether the federation client performs a partial state join.
21 changes: 18 additions & 3 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,11 @@ async def send_request(destination: str) -> Tuple[str, EventBase, RoomVersion]:
)

async def send_join(
self, destinations: Iterable[str], pdu: EventBase, room_version: RoomVersion
self,
destinations: Iterable[str],
pdu: EventBase,
room_version: RoomVersion,
partial_state: bool = True,
) -> SendJoinResult:
"""Sends a join event to one of a list of homeservers.

Expand All @@ -1027,6 +1031,10 @@ async def send_join(
pdu: event to be sent
room_version: the version of the room (according to the server that
did the make_join)
partial_state: whether to ask the remote server to omit membership state
events from the response. If the remote server complies,
`partial_state` in the send join result will be set. Defaults to
`True`.

Returns:
The result of the send join request.
Expand All @@ -1037,7 +1045,9 @@ async def send_join(
"""

async def send_request(destination: str) -> SendJoinResult:
response = await self._do_send_join(room_version, destination, pdu)
response = await self._do_send_join(
room_version, destination, pdu, omit_members=partial_state
)

# If an event was returned (and expected to be returned):
#
Expand Down Expand Up @@ -1177,7 +1187,11 @@ async def _execute(pdu: EventBase) -> None:
)

async def _do_send_join(
self, room_version: RoomVersion, destination: str, pdu: EventBase
self,
room_version: RoomVersion,
destination: str,
pdu: EventBase,
omit_members: bool,
) -> SendJoinResponse:
time_now = self._clock.time_msec()

Expand All @@ -1188,6 +1202,7 @@ async def _do_send_join(
room_id=pdu.room_id,
event_id=pdu.event_id,
content=pdu.get_pdu_json(time_now),
omit_members=omit_members,
)
except HttpResponseException as e:
# If an error is received that is due to an unrecognised endpoint,
Expand Down
7 changes: 5 additions & 2 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,16 @@ async def send_join_v2(
room_id: str,
event_id: str,
content: JsonDict,
omit_members: bool,
) -> "SendJoinResponse":
path = _create_v2_path("/send_join/%s/%s", room_id, event_id)
query_params: Dict[str, str] = {}
if self._faster_joins_enabled:
# lazy-load state on join
query_params["org.matrix.msc3706.partial_state"] = "true"
query_params["omit_members"] = "true"
query_params["org.matrix.msc3706.partial_state"] = (
"true" if omit_members else "false"
)
query_params["omit_members"] = "true" if omit_members else "false"

return await self.client.put_json(
destination=destination,
Expand Down