summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-07-19 12:09:39 +0100
committerGitHub <noreply@github.com>2024-07-19 12:09:39 +0100
commit43c865f7c98a1e31d6eb8d3979d1e199fadcb950 (patch)
treeeddb717eb4935d7866d3561fea3daa7275c30d79 /synapse
parentBump sentry-sdk from 2.6.0 to 2.8.0 (#17456) (diff)
downloadsynapse-43c865f7c98a1e31d6eb8d3979d1e199fadcb950.tar.xz
Generate room sync data concurrently (#17458)
This is also what we do for standard `/sync`.
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/sliding_sync.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py
index a23a6b9dd9..423f0329d6 100644
--- a/synapse/handlers/sliding_sync.py
+++ b/synapse/handlers/sliding_sync.py
@@ -28,6 +28,7 @@ from synapse.api.constants import AccountDataTypes, Direction, EventTypes, Membe
 from synapse.events import EventBase
 from synapse.events.utils import strip_event
 from synapse.handlers.relations import BundledAggregations
+from synapse.logging.opentracing import start_active_span, tag_args, trace
 from synapse.storage.databases.main.roommember import extract_heroes_from_room_summary
 from synapse.storage.databases.main.stream import CurrentStateDeltaMembership
 from synapse.storage.roommember import MemberSummary
@@ -43,6 +44,7 @@ from synapse.types import (
 )
 from synapse.types.handlers import OperationType, SlidingSyncConfig, SlidingSyncResult
 from synapse.types.state import StateFilter
+from synapse.util.async_helpers import concurrently_execute
 from synapse.visibility import filter_events_for_client
 
 if TYPE_CHECKING:
@@ -592,11 +594,14 @@ class SlidingSyncHandler:
 
         # Fetch room data
         rooms: Dict[str, SlidingSyncResult.RoomResult] = {}
-        for room_id, room_sync_config in relevant_room_map.items():
+
+        @trace
+        @tag_args
+        async def handle_room(room_id: str) -> None:
             room_sync_result = await self.get_room_sync_data(
                 user=sync_config.user,
                 room_id=room_id,
-                room_sync_config=room_sync_config,
+                room_sync_config=relevant_room_map[room_id],
                 room_membership_for_user_at_to_token=room_membership_for_user_map[
                     room_id
                 ],
@@ -606,6 +611,9 @@ class SlidingSyncHandler:
 
             rooms[room_id] = room_sync_result
 
+        with start_active_span("sliding_sync.generate_room_entries"):
+            await concurrently_execute(handle_room, relevant_room_map, 10)
+
         extensions = await self.get_extensions_response(
             sync_config=sync_config, to_token=to_token
         )