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

Avoid unnecessary work in the spaces summary. #10085

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Return early to reduce indent.
  • Loading branch information
clokep committed Jun 15, 2021
commit e9486328125a9bd2044ef9a54598368123626b0d
43 changes: 22 additions & 21 deletions synapse/handlers/space_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,29 +340,30 @@ async def _summarize_local_room(

room_entry = await self._build_room_entry(room_id)

# If the the room is a space, check if there are any children.
# If the the room is not a space, return just the room information.
if room_entry.get("room_type") != RoomTypes.SPACE:
return room_entry, ()

# Otherwise, look for child rooms/spaces.
child_events = await self._get_child_events(room_id)

if suggested_only:
# we only care about suggested children
child_events = filter(_is_suggested_child_event, child_events)

if max_children is None or max_children > MAX_ROOMS_PER_SPACE:
max_children = MAX_ROOMS_PER_SPACE

events_result = [] # type: List[JsonDict]
if room_entry.get("room_type") == RoomTypes.SPACE:

# look for child rooms/spaces.
child_events = await self._get_child_events(room_id)

if suggested_only:
# we only care about suggested children
child_events = filter(_is_suggested_child_event, child_events)

if max_children is None or max_children > MAX_ROOMS_PER_SPACE:
max_children = MAX_ROOMS_PER_SPACE

now = self._clock.time_msec()
for edge_event in itertools.islice(child_events, max_children):
events_result.append(
await self._event_serializer.serialize_event(
edge_event,
time_now=now,
event_format=format_event_for_client_v2,
)
now = self._clock.time_msec()
for edge_event in itertools.islice(child_events, max_children):
events_result.append(
await self._event_serializer.serialize_event(
edge_event,
time_now=now,
event_format=format_event_for_client_v2,
)
)

return room_entry, events_result

Expand Down