mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 23:15:02 -04:00
Support the stable /hierarchy endpoint from MSC2946 (#11329)
This also makes additional updates where the implementation had drifted from the approved MSC. Unstable endpoints will be removed at a later data.
This commit is contained in:
parent
d08ef6f155
commit
a4521ce0a8
11 changed files with 134 additions and 51 deletions
|
@ -36,8 +36,9 @@ from synapse.api.errors import (
|
|||
SynapseError,
|
||||
UnsupportedRoomVersionError,
|
||||
)
|
||||
from synapse.api.ratelimiting import Ratelimiter
|
||||
from synapse.events import EventBase
|
||||
from synapse.types import JsonDict
|
||||
from synapse.types import JsonDict, Requester
|
||||
from synapse.util.caches.response_cache import ResponseCache
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -93,6 +94,9 @@ class RoomSummaryHandler:
|
|||
self._event_serializer = hs.get_event_client_serializer()
|
||||
self._server_name = hs.hostname
|
||||
self._federation_client = hs.get_federation_client()
|
||||
self._ratelimiter = Ratelimiter(
|
||||
store=self._store, clock=hs.get_clock(), rate_hz=5, burst_count=10
|
||||
)
|
||||
|
||||
# If a user tries to fetch the same page multiple times in quick succession,
|
||||
# only process the first attempt and return its result to subsequent requests.
|
||||
|
@ -249,7 +253,7 @@ class RoomSummaryHandler:
|
|||
|
||||
async def get_room_hierarchy(
|
||||
self,
|
||||
requester: str,
|
||||
requester: Requester,
|
||||
requested_room_id: str,
|
||||
suggested_only: bool = False,
|
||||
max_depth: Optional[int] = None,
|
||||
|
@ -276,6 +280,8 @@ class RoomSummaryHandler:
|
|||
Returns:
|
||||
The JSON hierarchy dictionary.
|
||||
"""
|
||||
await self._ratelimiter.ratelimit(requester)
|
||||
|
||||
# If a user tries to fetch the same page multiple times in quick succession,
|
||||
# only process the first attempt and return its result to subsequent requests.
|
||||
#
|
||||
|
@ -283,7 +289,7 @@ class RoomSummaryHandler:
|
|||
# to process multiple requests for the same page will result in errors.
|
||||
return await self._pagination_response_cache.wrap(
|
||||
(
|
||||
requester,
|
||||
requester.user.to_string(),
|
||||
requested_room_id,
|
||||
suggested_only,
|
||||
max_depth,
|
||||
|
@ -291,7 +297,7 @@ class RoomSummaryHandler:
|
|||
from_token,
|
||||
),
|
||||
self._get_room_hierarchy,
|
||||
requester,
|
||||
requester.user.to_string(),
|
||||
requested_room_id,
|
||||
suggested_only,
|
||||
max_depth,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue