0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 16:13:50 +01:00

Optimise createRoom with multiple invites (#8559)

By not dropping the membership lock between invites, we can stop joins from
grabbing the lock when we're half-done and slowing the whole thing down.
This commit is contained in:
Richard van der Hoff 2020-10-29 11:48:39 +00:00 committed by GitHub
parent 00b24aa545
commit 56f0ee78a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 13 deletions

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

@ -0,0 +1 @@
Optimise `/createRoom` with multiple invited users.

View file

@ -771,22 +771,29 @@ class RoomCreationHandler(BaseHandler):
ratelimit=False, 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 = {} content = {}
is_direct = config.get("is_direct", None) is_direct = config.get("is_direct", None)
if is_direct: if is_direct:
content["is_direct"] = is_direct content["is_direct"] = is_direct
# Note that update_membership with an action of "invite" can raise a for invitee in invite_list:
# ShadowBanError, but this was handled above by emptying invite_list. (
_, last_stream_id = await self.room_member_handler.update_membership( _,
requester, last_stream_id,
UserID.from_string(invitee), ) = await self.room_member_handler.update_membership_locked(
room_id, requester,
"invite", UserID.from_string(invitee),
ratelimit=False, room_id,
content=content, "invite",
) ratelimit=False,
content=content,
)
for invite_3pid in invite_3pid_list: for invite_3pid in invite_3pid_list:
id_server = invite_3pid["id_server"] id_server = invite_3pid["id_server"]

View file

@ -307,7 +307,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
key = (room_id,) key = (room_id,)
with (await self.member_linearizer.queue(key)): with (await self.member_linearizer.queue(key)):
result = await self._update_membership( result = await self.update_membership_locked(
requester, requester,
target, target,
room_id, room_id,
@ -322,7 +322,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
return result return result
async def _update_membership( async def update_membership_locked(
self, self,
requester: Requester, requester: Requester,
target: UserID, target: UserID,
@ -335,6 +335,10 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
content: Optional[dict] = None, content: Optional[dict] = None,
require_consent: bool = True, require_consent: bool = True,
) -> Tuple[str, int]: ) -> Tuple[str, int]:
"""Helper for update_membership.
Assumes that the membership linearizer is already held for the room.
"""
content_specified = bool(content) content_specified = bool(content)
if content is None: if content is None:
content = {} content = {}