mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Rename get_events->get_events_from_store_or_dest (#5344)
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.
This commit is contained in:
parent
f6dd12d1e2
commit
b4189b112f
1
changelog.d/5344.misc
Normal file
1
changelog.d/5344.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Clean up FederationClient.get_events for clarity.
|
@ -17,7 +17,6 @@
|
|||||||
import copy
|
import copy
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import random
|
|
||||||
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -326,8 +325,8 @@ class FederationClient(FederationBase):
|
|||||||
state_event_ids = result["pdu_ids"]
|
state_event_ids = result["pdu_ids"]
|
||||||
auth_event_ids = result.get("auth_chain_ids", [])
|
auth_event_ids = result.get("auth_chain_ids", [])
|
||||||
|
|
||||||
fetched_events, failed_to_fetch = yield self.get_events(
|
fetched_events, failed_to_fetch = yield self.get_events_from_store_or_dest(
|
||||||
[destination], room_id, set(state_event_ids + auth_event_ids)
|
destination, room_id, set(state_event_ids + auth_event_ids)
|
||||||
)
|
)
|
||||||
|
|
||||||
if failed_to_fetch:
|
if failed_to_fetch:
|
||||||
@ -397,27 +396,20 @@ class FederationClient(FederationBase):
|
|||||||
defer.returnValue((signed_pdus, signed_auth))
|
defer.returnValue((signed_pdus, signed_auth))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_events(self, destinations, room_id, event_ids, return_local=True):
|
def get_events_from_store_or_dest(self, destination, room_id, event_ids):
|
||||||
"""Fetch events from some remote destinations, checking if we already
|
"""Fetch events from a remote destination, checking if we already have them.
|
||||||
have them.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
destinations (list)
|
destination (str)
|
||||||
room_id (str)
|
room_id (str)
|
||||||
event_ids (list)
|
event_ids (list)
|
||||||
return_local (bool): Whether to include events we already have in
|
|
||||||
the DB in the returned list of events
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Deferred: A deferred resolving to a 2-tuple where the first is a list of
|
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.
|
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)
|
seen_events = yield self.store.get_events(event_ids, allow_rejected=True)
|
||||||
signed_events = list(seen_events.values())
|
signed_events = list(seen_events.values())
|
||||||
else:
|
|
||||||
seen_events = yield self.store.have_seen_events(event_ids)
|
|
||||||
signed_events = []
|
|
||||||
|
|
||||||
failed_to_fetch = set()
|
failed_to_fetch = set()
|
||||||
|
|
||||||
@ -428,10 +420,11 @@ class FederationClient(FederationBase):
|
|||||||
if not missing_events:
|
if not missing_events:
|
||||||
defer.returnValue((signed_events, failed_to_fetch))
|
defer.returnValue((signed_events, failed_to_fetch))
|
||||||
|
|
||||||
def random_server_list():
|
logger.debug(
|
||||||
srvs = list(destinations)
|
"Fetching unknown state/auth events %s for room %s",
|
||||||
random.shuffle(srvs)
|
missing_events,
|
||||||
return srvs
|
event_ids,
|
||||||
|
)
|
||||||
|
|
||||||
room_version = yield self.store.get_room_version(room_id)
|
room_version = yield self.store.get_room_version(room_id)
|
||||||
|
|
||||||
@ -443,7 +436,7 @@ class FederationClient(FederationBase):
|
|||||||
deferreds = [
|
deferreds = [
|
||||||
run_in_background(
|
run_in_background(
|
||||||
self.get_pdu,
|
self.get_pdu,
|
||||||
destinations=random_server_list(),
|
destinations=[destination],
|
||||||
event_id=e_id,
|
event_id=e_id,
|
||||||
room_version=room_version,
|
room_version=room_version,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user