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

Commit fc2286e

Browse files
committed
Avoid checking the event cache when backfilling events
1 parent 6136768 commit fc2286e

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

synapse/handlers/federation_event.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,41 @@ async def _process_pulled_events(
792792
],
793793
)
794794

795+
# Check if we already any of these have these events.
796+
# Note: we currently make a lookup in the database directly here rather than
797+
# checking the event cache, due to:
798+
# https://github.com/matrix-org/synapse/issues/13476
799+
existing_events_map = await self._store._get_events_from_db(
800+
[event.event_id for event in events]
801+
)
802+
803+
new_events = []
804+
for event in events:
805+
event_id = event.event_id
806+
807+
# If we've already seen this event ID...
808+
if event_id in existing_events_map:
809+
existing_event = existing_events_map[event_id]
810+
811+
# ...and the event itself was not previously stored as an outlier...
812+
if not existing_event.event.internal_metadata.is_outlier():
813+
# ...then there's no need to persist it. We have it already.
814+
logger.info(
815+
"_process_pulled_event: Ignoring received event %s which we "
816+
"have already seen",
817+
event.event_id,
818+
)
819+
820+
# While we have seen this event before, it was stored as an outlier.
821+
# We'll now persist it as a non-outlier.
822+
logger.info("De-outliering event %s", event_id)
823+
824+
# Continue on with the events that are new to us.
825+
new_events.append(event)
826+
795827
# We want to sort these by depth so we process them and
796828
# tell clients about them in order.
797-
sorted_events = sorted(events, key=lambda x: x.depth)
829+
sorted_events = sorted(new_events, key=lambda x: x.depth)
798830
for ev in sorted_events:
799831
with nested_logging_context(ev.event_id):
800832
await self._process_pulled_event(origin, ev, backfilled=backfilled)
@@ -846,18 +878,6 @@ async def _process_pulled_event(
846878

847879
event_id = event.event_id
848880

849-
existing = await self._store.get_event(
850-
event_id, allow_none=True, allow_rejected=True
851-
)
852-
if existing:
853-
if not existing.internal_metadata.is_outlier():
854-
logger.info(
855-
"_process_pulled_event: Ignoring received event %s which we have already seen",
856-
event_id,
857-
)
858-
return
859-
logger.info("De-outliering event %s", event_id)
860-
861881
try:
862882
self._sanity_check_event(event)
863883
except SynapseError as err:

0 commit comments

Comments
 (0)