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

Commit

Permalink
Reduce the duplication of code that invokes the rate limiter. (#13070)
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre authored Jun 16, 2022
1 parent 1e0044e commit 7552615
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.d/13070.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce the duplication of code that invokes the rate limiter.
30 changes: 3 additions & 27 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@
GuestAccess,
Membership,
)
from synapse.api.errors import (
AuthError,
Codes,
LimitExceededError,
ShadowBanError,
SynapseError,
)
from synapse.api.errors import AuthError, Codes, ShadowBanError, SynapseError
from synapse.api.ratelimiting import Ratelimiter
from synapse.event_auth import get_named_level, get_power_level_event
from synapse.events import EventBase
Expand Down Expand Up @@ -380,16 +374,7 @@ async def _local_membership_update(
# Only rate-limit if the user actually joined the room, otherwise we'll end
# up blocking profile updates.
if newly_joined and ratelimit:
time_now_s = self.clock.time()
(
allowed,
time_allowed,
) = await self._join_rate_limiter_local.can_do_action(requester)

if not allowed:
raise LimitExceededError(
retry_after_ms=int(1000 * (time_allowed - time_now_s))
)
await self._join_rate_limiter_local.ratelimit(requester)

result_event = await self.event_creation_handler.handle_new_client_event(
requester,
Expand Down Expand Up @@ -835,19 +820,10 @@ async def update_membership_locked(
)
if remote_join:
if ratelimit:
time_now_s = self.clock.time()
(
allowed,
time_allowed,
) = await self._join_rate_limiter_remote.can_do_action(
await self._join_rate_limiter_remote.ratelimit(
requester,
)

if not allowed:
raise LimitExceededError(
retry_after_ms=int(1000 * (time_allowed - time_now_s))
)

inviter = await self._get_inviter(target.to_string(), room_id)
if inviter and not self.hs.is_mine(inviter):
remote_room_hosts.append(inviter.domain)
Expand Down

0 comments on commit 7552615

Please sign in to comment.