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

Commit

Permalink
Merge pull request #2170 from matrix-org/erikj/fed_hole_state
Browse files Browse the repository at this point in the history
Don't fetch state for missing events that we fetched
  • Loading branch information
erikjohnston authored May 3, 2017
2 parents e4c15fc + ef86218 commit 0c27383
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,23 @@ def on_receive_pdu(self, origin, pdu, get_missing=True):
yield self._get_missing_events_for_pdu(
origin, pdu, prevs, min_depth
)

# Update the set of things we've seen after trying to
# fetch the missing stuff
have_seen = yield self.store.have_events(prevs)
seen = set(have_seen.iterkeys())

if not prevs - seen:
logger.info(
"Found all missing prev events for %s", pdu.event_id
)
elif prevs - seen:
logger.info(
"Not fetching %d missing events for room %r,event %s: %r...",
len(prevs - seen), pdu.room_id, pdu.event_id,
list(prevs - seen)[:5],
)

prevs = {e_id for e_id, _ in pdu.prev_events}
seen = set(have_seen.keys())
if prevs - seen:
logger.info(
"Still missing %d events for room %r: %r...",
Expand Down Expand Up @@ -214,19 +222,15 @@ def _get_missing_events_for_pdu(self, origin, pdu, prevs, min_depth):
Args:
origin (str): Origin of the pdu. Will be called to get the missing events
pdu: received pdu
prevs (str[]): List of event ids which we are missing
prevs (set(str)): List of event ids which we are missing
min_depth (int): Minimum depth of events to return.
Returns:
Deferred<dict(str, str?)>: updated have_seen dictionary
"""
# We recalculate seen, since it may have changed.
have_seen = yield self.store.have_events(prevs)
seen = set(have_seen.keys())

if not prevs - seen:
# nothing left to do
defer.returnValue(have_seen)
return

latest = yield self.store.get_latest_event_ids_in_room(
pdu.room_id
Expand Down Expand Up @@ -288,19 +292,6 @@ def _get_missing_events_for_pdu(self, origin, pdu, prevs, min_depth):
get_missing=False
)

have_seen = yield self.store.have_events(
[ev for ev, _ in pdu.prev_events]
)
seen = set(have_seen.keys())
if prevs - seen:
logger.info(
"Still missing %d prev events for %s: %r...",
len(prevs - seen), pdu.event_id, list(prevs - seen)[:5]
)
else:
logger.info("Found all missing prev events for %s", pdu.event_id)
defer.returnValue(have_seen)

@log_function
@defer.inlineCallbacks
def _process_received_pdu(self, origin, pdu, state, auth_chain):
Expand Down

0 comments on commit 0c27383

Please sign in to comment.