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

Commit

Permalink
Avoid state lookups for events we'll ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Mar 10, 2023
1 parent cd0e272 commit b02fd01
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def check_event_is_visible(
# this check but would base the filtering on an outdated view of the membership events.

partial_state_invisible_event_ids: Set[str] = set()
maybe_visible_events: List[EventBase] = []
if filter_out_partial_state_rooms:
for e in events:
sender_domain = get_domain_from_id(e.sender)
Expand All @@ -664,33 +665,37 @@ def check_event_is_visible(
and await storage.main.is_partial_state_room(e.room_id)
):
partial_state_invisible_event_ids.add(e.event_id)
else:
maybe_visible_events.append(e)
else:
maybe_visible_events = events

# Let's check to see if all the events have a history visibility
# of "shared" or "world_readable". If that's the case then we don't
# need to check membership (as we know the server is in the room).
event_to_history_vis = await _event_to_history_vis(storage, events)
event_to_history_vis = await _event_to_history_vis(storage, maybe_visible_events)

# for any with restricted vis, we also need the memberships
event_to_memberships = await _event_to_memberships(
storage,
[
e
for e in events
for e in maybe_visible_events
if event_to_history_vis[e.event_id]
not in (HistoryVisibility.SHARED, HistoryVisibility.WORLD_READABLE)
],
target_server_name,
)

def include_event_in_output(e: EventBase) -> bool:
if e.event_id in partial_state_invisible_event_ids:
return False

erased = is_sender_erased(e, erased_senders)
visible = check_event_is_visible(
event_to_history_vis[e.event_id], event_to_memberships.get(e.event_id, {})
)

if e.event_id in partial_state_invisible_event_ids:
visible = False

return visible and not erased

to_return = []
Expand Down

0 comments on commit b02fd01

Please sign in to comment.