diff options
author | Andrew Morgan <andrewm@element.io> | 2022-10-12 18:11:00 +0100 |
---|---|---|
committer | Andrew Morgan <andrewm@element.io> | 2022-10-12 18:11:40 +0100 |
commit | fc2286e9d402e8f94ed2892918e8c13e21a70293 (patch) | |
tree | 541976721e2cc1bed783319ca8dff868928a7f71 | |
parent | Remove the groups config code. (#14142) (diff) | |
download | synapse-fc2286e9d402e8f94ed2892918e8c13e21a70293.tar.xz |
Avoid checking the event cache when backfilling events
-rw-r--r-- | synapse/handlers/federation_event.py | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/synapse/handlers/federation_event.py b/synapse/handlers/federation_event.py index da319943cc..a84c65fd31 100644 --- a/synapse/handlers/federation_event.py +++ b/synapse/handlers/federation_event.py @@ -792,9 +792,41 @@ class FederationEventHandler: ], ) + # Check if we already any of these have these events. + # Note: we currently make a lookup in the database directly here rather than + # checking the event cache, due to: + # https://github.com/matrix-org/synapse/issues/13476 + existing_events_map = await self._store._get_events_from_db( + [event.event_id for event in events] + ) + + new_events = [] + for event in events: + event_id = event.event_id + + # If we've already seen this event ID... + if event_id in existing_events_map: + existing_event = existing_events_map[event_id] + + # ...and the event itself was not previously stored as an outlier... + if not existing_event.event.internal_metadata.is_outlier(): + # ...then there's no need to persist it. We have it already. + logger.info( + "_process_pulled_event: Ignoring received event %s which we " + "have already seen", + event.event_id, + ) + + # While we have seen this event before, it was stored as an outlier. + # We'll now persist it as a non-outlier. + logger.info("De-outliering event %s", event_id) + + # Continue on with the events that are new to us. + new_events.append(event) + # We want to sort these by depth so we process them and # tell clients about them in order. - sorted_events = sorted(events, key=lambda x: x.depth) + sorted_events = sorted(new_events, key=lambda x: x.depth) for ev in sorted_events: with nested_logging_context(ev.event_id): await self._process_pulled_event(origin, ev, backfilled=backfilled) @@ -846,18 +878,6 @@ class FederationEventHandler: event_id = event.event_id - existing = await self._store.get_event( - event_id, allow_none=True, allow_rejected=True - ) - if existing: - if not existing.internal_metadata.is_outlier(): - logger.info( - "_process_pulled_event: Ignoring received event %s which we have already seen", - event_id, - ) - return - logger.info("De-outliering event %s", event_id) - try: self._sanity_check_event(event) except SynapseError as err: |