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

Refactor filter_events_for_server #15240

Merged
merged 8 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add explicit option for partial state rooms
  • Loading branch information
David Robertson committed Mar 10, 2023
commit 85a98b1023a330c4c6179cc5c5660fbb54d5bb51
1 change: 1 addition & 0 deletions synapse/federation/sender/per_destination_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ async def _catch_up_transmission_loop(self) -> None:
new_pdus,
redact=False,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)

# If we've filtered out all the extremities, fall back to
Expand Down
4 changes: 4 additions & 0 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ async def _maybe_backfill_inner(
events_to_check,
redact=False,
filter_out_erased_senders=False,
filter_out_partial_state_rooms=False,
)
if filtered_extremities:
extremities_to_request.append(bp.event_id)
Expand Down Expand Up @@ -1337,6 +1338,7 @@ async def on_backfill_request(
events,
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)

return events
Expand Down Expand Up @@ -1373,6 +1375,7 @@ async def get_persisted_pdu(
[event],
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)
event = events[0]
return event
Expand Down Expand Up @@ -1406,6 +1409,7 @@ async def on_get_missing_events(
missing_events,
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)

return missing_events
Expand Down
6 changes: 4 additions & 2 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ async def filter_events_for_server(
*,
redact: bool,
filter_out_erased_senders: bool,
filter_out_partial_state_rooms: bool,
) -> List[EventBase]:
"""Filter a list of events based on whether the target server is allowed to
see them.
Expand All @@ -604,7 +605,8 @@ async def filter_events_for_server(
filter_out_erased_senders: If true, also filter out events whose sender has been
erased. This is used e.g. during pagination to decide whether to
backfill or not.

filter_out_partial_state_rooms: If True, also filter out events in partial state
rooms.
Returns
The filtered events.
"""
Expand Down Expand Up @@ -654,7 +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()
if filter_out_erased_senders:
if filter_out_partial_state_rooms:
for e in events:
sender_domain = get_domain_from_id(e.sender)
if (
Expand Down
5 changes: 5 additions & 0 deletions tests/test_visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_filtering(self) -> None:
events_to_filter,
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)
)

Expand Down Expand Up @@ -96,6 +97,7 @@ def test_filter_outlier(self) -> None:
[outlier],
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)
),
[outlier],
Expand All @@ -112,6 +114,7 @@ def test_filter_outlier(self) -> None:
[outlier, evt],
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)
)
self.assertEqual(len(filtered), 2, f"expected 2 results, got: {filtered}")
Expand All @@ -129,6 +132,7 @@ def test_filter_outlier(self) -> None:
[outlier, evt],
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)
)
self.assertEqual(filtered[0], outlier)
Expand Down Expand Up @@ -169,6 +173,7 @@ def test_erased_user(self) -> None:
events_to_filter,
redact=True,
filter_out_erased_senders=True,
filter_out_partial_state_rooms=True,
)
)

Expand Down