mirror of
https://github.com/matrix-org/synapse.git
synced 2025-02-23 15:45:47 +00:00
Expire old spaces summary pagination sessions. (#10574)
This commit is contained in:
parent
2ae2a04616
commit
5acd8b5a96
1
changelog.d/10574.feature
Normal file
1
changelog.d/10574.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add pagination to the spaces summary based on updates to [MSC2946](https://github.com/matrix-org/matrix-doc/pull/2946).
|
@ -77,6 +77,8 @@ class _PaginationKey:
|
|||||||
class _PaginationSession:
|
class _PaginationSession:
|
||||||
"""The information that is stored for pagination."""
|
"""The information that is stored for pagination."""
|
||||||
|
|
||||||
|
# The time the pagination session was created, in milliseconds.
|
||||||
|
creation_time_ms: int
|
||||||
# The queue of rooms which are still to process.
|
# The queue of rooms which are still to process.
|
||||||
room_queue: Deque["_RoomQueueEntry"]
|
room_queue: Deque["_RoomQueueEntry"]
|
||||||
# A set of rooms which have been processed.
|
# A set of rooms which have been processed.
|
||||||
@ -84,6 +86,9 @@ class _PaginationSession:
|
|||||||
|
|
||||||
|
|
||||||
class SpaceSummaryHandler:
|
class SpaceSummaryHandler:
|
||||||
|
# The time a pagination session remains valid for.
|
||||||
|
_PAGINATION_SESSION_VALIDITY_PERIOD_MS = 5 * 60 * 1000
|
||||||
|
|
||||||
def __init__(self, hs: "HomeServer"):
|
def __init__(self, hs: "HomeServer"):
|
||||||
self._clock = hs.get_clock()
|
self._clock = hs.get_clock()
|
||||||
self._auth = hs.get_auth()
|
self._auth = hs.get_auth()
|
||||||
@ -108,6 +113,21 @@ class SpaceSummaryHandler:
|
|||||||
"get_room_hierarchy",
|
"get_room_hierarchy",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _expire_pagination_sessions(self):
|
||||||
|
"""Expire pagination session which are old."""
|
||||||
|
expire_before = (
|
||||||
|
self._clock.time_msec() - self._PAGINATION_SESSION_VALIDITY_PERIOD_MS
|
||||||
|
)
|
||||||
|
to_expire = []
|
||||||
|
|
||||||
|
for key, value in self._pagination_sessions.items():
|
||||||
|
if value.creation_time_ms < expire_before:
|
||||||
|
to_expire.append(key)
|
||||||
|
|
||||||
|
for key in to_expire:
|
||||||
|
logger.debug("Expiring pagination session id %s", key)
|
||||||
|
del self._pagination_sessions[key]
|
||||||
|
|
||||||
async def get_space_summary(
|
async def get_space_summary(
|
||||||
self,
|
self,
|
||||||
requester: str,
|
requester: str,
|
||||||
@ -312,6 +332,8 @@ class SpaceSummaryHandler:
|
|||||||
|
|
||||||
# If this is continuing a previous session, pull the persisted data.
|
# If this is continuing a previous session, pull the persisted data.
|
||||||
if from_token:
|
if from_token:
|
||||||
|
self._expire_pagination_sessions()
|
||||||
|
|
||||||
pagination_key = _PaginationKey(
|
pagination_key = _PaginationKey(
|
||||||
requested_room_id, suggested_only, max_depth, from_token
|
requested_room_id, suggested_only, max_depth, from_token
|
||||||
)
|
)
|
||||||
@ -391,7 +413,7 @@ class SpaceSummaryHandler:
|
|||||||
requested_room_id, suggested_only, max_depth, next_token
|
requested_room_id, suggested_only, max_depth, next_token
|
||||||
)
|
)
|
||||||
self._pagination_sessions[pagination_key] = _PaginationSession(
|
self._pagination_sessions[pagination_key] = _PaginationSession(
|
||||||
room_queue, processed_rooms
|
self._clock.time_msec(), room_queue, processed_rooms
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user