diff options
author | Erik Johnston <erik@matrix.org> | 2016-04-07 16:35:40 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-04-07 16:35:40 +0100 |
commit | a294b04bf09bb2292485f7946b6ae8854910dc24 (patch) | |
tree | 4639be3f9543b4a9090654f4ecc781d3b4398a6d /synapse/handlers/room_member.py | |
parent | Merge pull request #703 from matrix-org/erikj/member (diff) | |
parent | Rename things (diff) | |
download | synapse-a294b04bf09bb2292485f7946b6ae8854910dc24.tar.xz |
Merge pull request #700 from matrix-org/erikj/deduplicate_joins
Deduplicate membership changes
Diffstat (limited to 'synapse/handlers/room_member.py')
-rw-r--r-- | synapse/handlers/room_member.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index 8c41cb6f3c..b6ef3c91af 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -24,6 +24,7 @@ from synapse.api.constants import ( ) from synapse.api.errors import AuthError, SynapseError, Codes from synapse.util.logcontext import preserve_context_over_fn +from synapse.util.async import Linearizer from signedjson.sign import verify_signed_json from signedjson.key import decode_verify_key_bytes @@ -60,6 +61,8 @@ class RoomMemberHandler(BaseHandler): def __init__(self, hs): super(RoomMemberHandler, self).__init__(hs) + self.member_linearizer = Linearizer() + self.clock = hs.get_clock() self.distributor = hs.get_distributor() @@ -183,6 +186,34 @@ class RoomMemberHandler(BaseHandler): third_party_signed=None, ratelimit=True, ): + key = (target, room_id,) + + with (yield self.member_linearizer.queue(key)): + result = yield self._update_membership( + requester, + target, + room_id, + action, + txn_id=txn_id, + remote_room_hosts=remote_room_hosts, + third_party_signed=third_party_signed, + ratelimit=ratelimit, + ) + + defer.returnValue(result) + + @defer.inlineCallbacks + def _update_membership( + self, + requester, + target, + room_id, + action, + txn_id=None, + remote_room_hosts=None, + third_party_signed=None, + ratelimit=True, + ): effective_membership_state = action if action in ["kick", "unban"]: effective_membership_state = "leave" |