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

Commit

Permalink
Rename get_events->get_events_from_store_or_dest (#5344)
Browse files Browse the repository at this point in the history
We have too many things called get_event, and it's hard to figure out what we
mean. Also remove some unused params from the signature, and add some logging.
  • Loading branch information
richvdh authored Jun 4, 2019
1 parent f6dd12d commit b4189b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.d/5344.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up FederationClient.get_events for clarity.
33 changes: 13 additions & 20 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import copy
import itertools
import logging
import random

from six.moves import range

Expand Down Expand Up @@ -326,8 +325,8 @@ def get_state_for_room(self, destination, room_id, event_id):
state_event_ids = result["pdu_ids"]
auth_event_ids = result.get("auth_chain_ids", [])

fetched_events, failed_to_fetch = yield self.get_events(
[destination], room_id, set(state_event_ids + auth_event_ids)
fetched_events, failed_to_fetch = yield self.get_events_from_store_or_dest(
destination, room_id, set(state_event_ids + auth_event_ids)
)

if failed_to_fetch:
Expand Down Expand Up @@ -397,27 +396,20 @@ def get_state_for_room(self, destination, room_id, event_id):
defer.returnValue((signed_pdus, signed_auth))

@defer.inlineCallbacks
def get_events(self, destinations, room_id, event_ids, return_local=True):
"""Fetch events from some remote destinations, checking if we already
have them.
def get_events_from_store_or_dest(self, destination, room_id, event_ids):
"""Fetch events from a remote destination, checking if we already have them.
Args:
destinations (list)
destination (str)
room_id (str)
event_ids (list)
return_local (bool): Whether to include events we already have in
the DB in the returned list of events
Returns:
Deferred: A deferred resolving to a 2-tuple where the first is a list of
events and the second is a list of event ids that we failed to fetch.
"""
if return_local:
seen_events = yield self.store.get_events(event_ids, allow_rejected=True)
signed_events = list(seen_events.values())
else:
seen_events = yield self.store.have_seen_events(event_ids)
signed_events = []
seen_events = yield self.store.get_events(event_ids, allow_rejected=True)
signed_events = list(seen_events.values())

failed_to_fetch = set()

Expand All @@ -428,10 +420,11 @@ def get_events(self, destinations, room_id, event_ids, return_local=True):
if not missing_events:
defer.returnValue((signed_events, failed_to_fetch))

def random_server_list():
srvs = list(destinations)
random.shuffle(srvs)
return srvs
logger.debug(
"Fetching unknown state/auth events %s for room %s",
missing_events,
event_ids,
)

room_version = yield self.store.get_room_version(room_id)

Expand All @@ -443,7 +436,7 @@ def random_server_list():
deferreds = [
run_in_background(
self.get_pdu,
destinations=random_server_list(),
destinations=[destination],
event_id=e_id,
room_version=room_version,
)
Expand Down

0 comments on commit b4189b1

Please sign in to comment.