This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Faster joins: Refactor handling of servers in room #14954
Merged
squahtx
merged 4 commits into
develop
from
squah/faster_room_joins_refactor_servers_in_room
Feb 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,8 @@ class SendJoinResult: | |
# True if 'state' elides non-critical membership events | ||
partial_state: bool | ||
|
||
# if 'partial_state' is set, a list of the servers in the room (otherwise empty) | ||
# If 'partial_state' is set, a list of the servers in the room (otherwise empty). | ||
# Always contains the server we joined off. | ||
servers_in_room: List[str] | ||
|
||
|
||
|
@@ -1152,23 +1153,30 @@ async def _execute(pdu: EventBase) -> None: | |
% (auth_chain_create_events,) | ||
) | ||
|
||
if response.members_omitted and not response.servers_in_room: | ||
raise InvalidResponseError( | ||
"members_omitted was set, but no servers were listed in the room" | ||
) | ||
servers_in_room = response.servers_in_room | ||
if response.members_omitted: | ||
if not servers_in_room: | ||
raise InvalidResponseError( | ||
"members_omitted was set, but no servers were listed in the room" | ||
) | ||
|
||
if response.members_omitted and not partial_state: | ||
raise InvalidResponseError( | ||
"members_omitted was set, but we asked for full state" | ||
) | ||
if destination not in servers_in_room: | ||
# `servers_in_room` is supposed to be a complete list. | ||
# Fix things up if the remote homeserver is badly behaved. | ||
servers_in_room = [destination] + servers_in_room | ||
|
||
if not partial_state: | ||
raise InvalidResponseError( | ||
"members_omitted was set, but we asked for full state" | ||
) | ||
Comment on lines
+1167
to
+1170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend moving this above the destination check to have all the error checking up-front. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 163c68c. |
||
|
||
return SendJoinResult( | ||
event=event, | ||
state=signed_state, | ||
auth_chain=signed_auth, | ||
origin=destination, | ||
partial_state=response.members_omitted, | ||
servers_in_room=response.servers_in_room or [], | ||
servers_in_room=servers_in_room or [], | ||
) | ||
|
||
# MSC3083 defines additional error codes for room joins. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be making this a set? What if the remote server returns the same thing for
servers_in_room
100 times?Is it possible for
destination
to no longer be in the room at this point? (I'm guessing no because we just got a response from it?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. We'll fail to insert the list into the database, because there's a unique constraint. And the join will fail.
There's nothing stopping
destination
from leaving the room immediately after our join really.If
destination
leaves the room, we'll try syncing state from other servers in the list.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Representing the server list as a set sounds like a good idea, so I did it in 163c68c.