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

Optimise createRoom with multiple invites #8559

Merged
merged 3 commits into from
Oct 29, 2020
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/8559.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimise `/createRoom` with multiple invited users.
29 changes: 18 additions & 11 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,22 +762,29 @@ async def create_room(
ratelimit=False,
)

for invitee in invite_list:
# we avoid dropping the lock between invites, as otherwise joins can
# start coming in and making the createRoom slow.
#
# we also don't need to check the requester's shadow-ban here, as we
# have already done so above (and potentially emptied invite_list).
with (await self.room_member_handler.member_linearizer.queue((room_id,))):
content = {}
is_direct = config.get("is_direct", None)
if is_direct:
content["is_direct"] = is_direct

# Note that update_membership with an action of "invite" can raise a
# ShadowBanError, but this was handled above by emptying invite_list.
_, last_stream_id = await self.room_member_handler.update_membership(
requester,
UserID.from_string(invitee),
room_id,
"invite",
ratelimit=False,
content=content,
)
for invitee in invite_list:
(
_,
last_stream_id,
) = await self.room_member_handler.update_membership_locked(
requester,
UserID.from_string(invitee),
room_id,
"invite",
ratelimit=False,
content=content,
)

for invite_3pid in invite_3pid_list:
id_server = invite_3pid["id_server"]
Expand Down
8 changes: 6 additions & 2 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async def update_membership(
key = (room_id,)

with (await self.member_linearizer.queue(key)):
result = await self._update_membership(
result = await self.update_membership_locked(
requester,
target,
room_id,
Expand All @@ -325,7 +325,7 @@ async def update_membership(

return result

async def _update_membership(
async def update_membership_locked(
self,
requester: Requester,
target: UserID,
Expand All @@ -338,6 +338,10 @@ async def _update_membership(
content: Optional[dict] = None,
require_consent: bool = True,
) -> Tuple[str, int]:
"""Helper for update_membership.

Assumes that the membership linearizer is already held for the room.
"""
content_specified = bool(content)
if content is None:
content = {}
Expand Down