mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-18 07:52:56 +01:00
Limit concurrent AS joins
This commit is contained in:
parent
43bb12e640
commit
e5537cf983
1 changed files with 19 additions and 13 deletions
|
@ -31,7 +31,7 @@ from synapse.api.constants import (
|
||||||
)
|
)
|
||||||
from synapse.api.errors import AuthError, SynapseError, Codes
|
from synapse.api.errors import AuthError, SynapseError, Codes
|
||||||
from synapse.types import UserID, RoomID
|
from synapse.types import UserID, RoomID
|
||||||
from synapse.util.async import Linearizer
|
from synapse.util.async import Linearizer, Limiter
|
||||||
from synapse.util.distributor import user_left_room, user_joined_room
|
from synapse.util.distributor import user_left_room, user_joined_room
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class RoomMemberHandler(object):
|
||||||
self.event_creation_hander = hs.get_event_creation_handler()
|
self.event_creation_hander = hs.get_event_creation_handler()
|
||||||
|
|
||||||
self.member_linearizer = Linearizer(name="member")
|
self.member_linearizer = Linearizer(name="member")
|
||||||
|
self.member_limiter = Limiter(3)
|
||||||
|
|
||||||
self.clock = hs.get_clock()
|
self.clock = hs.get_clock()
|
||||||
self.spam_checker = hs.get_spam_checker()
|
self.spam_checker = hs.get_spam_checker()
|
||||||
|
@ -241,18 +242,23 @@ class RoomMemberHandler(object):
|
||||||
):
|
):
|
||||||
key = (room_id,)
|
key = (room_id,)
|
||||||
|
|
||||||
with (yield self.member_linearizer.queue(key)):
|
as_id = object()
|
||||||
result = yield self._update_membership(
|
if requester.app_service:
|
||||||
requester,
|
as_id = requester.app_service.id
|
||||||
target,
|
|
||||||
room_id,
|
with (yield self.member_limiter.queue(as_id)):
|
||||||
action,
|
with (yield self.member_linearizer.queue(key)):
|
||||||
txn_id=txn_id,
|
result = yield self._update_membership(
|
||||||
remote_room_hosts=remote_room_hosts,
|
requester,
|
||||||
third_party_signed=third_party_signed,
|
target,
|
||||||
ratelimit=ratelimit,
|
room_id,
|
||||||
content=content,
|
action,
|
||||||
)
|
txn_id=txn_id,
|
||||||
|
remote_room_hosts=remote_room_hosts,
|
||||||
|
third_party_signed=third_party_signed,
|
||||||
|
ratelimit=ratelimit,
|
||||||
|
content=content,
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue