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

Add a cache around server ACL checking #16360

Merged
merged 13 commits into from
Sep 26, 2023
12 changes: 11 additions & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
from synapse.types import JsonDict, StateMap, get_domain_from_id
from synapse.util import unwrapFirstError
from synapse.util.async_helpers import Linearizer, concurrently_execute, gather_results
from synapse.util.caches.descriptors import cached
from synapse.util.caches.response_cache import ResponseCache
from synapse.util.stringutils import parse_server_name

Expand Down Expand Up @@ -1375,10 +1376,19 @@ async def check_server_matches_acl(self, server_name: str, room_id: str) -> None
room_id, EventTypes.ServerACL, ""
)
if acl_event:
server_acl_evaluator = server_acl_evaluator_from_event(acl_event)
server_acl_evaluator = await self._get_server_acl_evaluator(
acl_event.event_id, acl_event
)
if not server_acl_evaluator.server_matches_acl_event(server_name):
raise AuthError(code=403, msg="Server is banned from room")

@cached(uncached_args=("acl_event",))
def _get_server_acl_evaluator(
self, event_id: str, acl_event: EventBase
) -> ServerAclEvaluator:
clokep marked this conversation as resolved.
Show resolved Hide resolved
"""Create a ServerAclEvaluator from an event, but cached on the event ID."""
return server_acl_evaluator_from_event(acl_event)
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved


def server_acl_evaluator_from_event(acl_event: EventBase) -> "ServerAclEvaluator":
"""
Expand Down