From 287a9c1e20e1e271d69be581d6bb8ee5a8de9d88 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 28 Mar 2022 19:20:14 +0100 Subject: [PATCH] Exclude outliers in `on_backfill_request` (#12314) When we are processing a `/backfill` request from a remote server, exclude any outliers from consideration early on. We can't return outliers anyway (since we don't know the state at the outlier), and filtering them out earlier means that we won't attempt to calulate the state for them. --- changelog.d/12314.misc | 1 + synapse/storage/databases/main/event_federation.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 changelog.d/12314.misc diff --git a/changelog.d/12314.misc b/changelog.d/12314.misc new file mode 100644 index 0000000000..9f333e718a --- /dev/null +++ b/changelog.d/12314.misc @@ -0,0 +1 @@ +Avoid trying to calculate the state at outlier events. diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py index 277e6422eb..634e19e035 100644 --- a/synapse/storage/databases/main/event_federation.py +++ b/synapse/storage/databases/main/event_federation.py @@ -1073,9 +1073,15 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas /* Get the depth and stream_ordering of the prev_event_id from the events table */ INNER JOIN events ON prev_event_id = events.event_id + + /* exclude outliers from the results (we don't have the state, so cannot + * verify if the requesting server can see them). + */ + WHERE NOT events.outlier + /* Look for an edge which matches the given event_id */ - WHERE event_edges.event_id = ? - AND event_edges.is_state = ? + AND event_edges.event_id = ? AND NOT event_edges.is_state + /* Because we can have many events at the same depth, * we want to also tie-break and sort on stream_ordering */ ORDER BY depth DESC, stream_ordering DESC @@ -1084,7 +1090,7 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas txn.execute( connected_prev_event_query, - (event_id, False, limit), + (event_id, limit), ) return [ BackfillQueueNavigationItem(