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

Commit 7552615

Browse files
authored
Reduce the duplication of code that invokes the rate limiter. (#13070)
1 parent 1e0044e commit 7552615

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

changelog.d/13070.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce the duplication of code that invokes the rate limiter.

synapse/handlers/room_member.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@
2626
GuestAccess,
2727
Membership,
2828
)
29-
from synapse.api.errors import (
30-
AuthError,
31-
Codes,
32-
LimitExceededError,
33-
ShadowBanError,
34-
SynapseError,
35-
)
29+
from synapse.api.errors import AuthError, Codes, ShadowBanError, SynapseError
3630
from synapse.api.ratelimiting import Ratelimiter
3731
from synapse.event_auth import get_named_level, get_power_level_event
3832
from synapse.events import EventBase
@@ -380,16 +374,7 @@ async def _local_membership_update(
380374
# Only rate-limit if the user actually joined the room, otherwise we'll end
381375
# up blocking profile updates.
382376
if newly_joined and ratelimit:
383-
time_now_s = self.clock.time()
384-
(
385-
allowed,
386-
time_allowed,
387-
) = await self._join_rate_limiter_local.can_do_action(requester)
388-
389-
if not allowed:
390-
raise LimitExceededError(
391-
retry_after_ms=int(1000 * (time_allowed - time_now_s))
392-
)
377+
await self._join_rate_limiter_local.ratelimit(requester)
393378

394379
result_event = await self.event_creation_handler.handle_new_client_event(
395380
requester,
@@ -835,19 +820,10 @@ async def update_membership_locked(
835820
)
836821
if remote_join:
837822
if ratelimit:
838-
time_now_s = self.clock.time()
839-
(
840-
allowed,
841-
time_allowed,
842-
) = await self._join_rate_limiter_remote.can_do_action(
823+
await self._join_rate_limiter_remote.ratelimit(
843824
requester,
844825
)
845826

846-
if not allowed:
847-
raise LimitExceededError(
848-
retry_after_ms=int(1000 * (time_allowed - time_now_s))
849-
)
850-
851827
inviter = await self._get_inviter(target.to_string(), room_id)
852828
if inviter and not self.hs.is_mine(inviter):
853829
remote_room_hosts.append(inviter.domain)

0 commit comments

Comments
 (0)