mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Merge pull request #3428 from matrix-org/erikj/persisted_pdu
Simplify get_persisted_pdu
This commit is contained in:
commit
b4a5d767a9
@ -277,7 +277,7 @@ class FederationServer(FederationBase):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def on_pdu_request(self, origin, event_id):
|
def on_pdu_request(self, origin, event_id):
|
||||||
pdu = yield self._get_persisted_pdu(origin, event_id)
|
pdu = yield self.handler.get_persisted_pdu(origin, event_id)
|
||||||
|
|
||||||
if pdu:
|
if pdu:
|
||||||
defer.returnValue(
|
defer.returnValue(
|
||||||
@ -470,17 +470,6 @@ class FederationServer(FederationBase):
|
|||||||
ts_now_ms = self._clock.time_msec()
|
ts_now_ms = self._clock.time_msec()
|
||||||
return self.store.get_user_id_for_open_id_token(token, ts_now_ms)
|
return self.store.get_user_id_for_open_id_token(token, ts_now_ms)
|
||||||
|
|
||||||
@log_function
|
|
||||||
def _get_persisted_pdu(self, origin, event_id, do_auth=True):
|
|
||||||
""" Get a PDU from the database with given origin and id.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Deferred: Results in a `Pdu`.
|
|
||||||
"""
|
|
||||||
return self.handler.get_persisted_pdu(
|
|
||||||
origin, event_id, do_auth=do_auth
|
|
||||||
)
|
|
||||||
|
|
||||||
def _transaction_from_pdus(self, pdu_list):
|
def _transaction_from_pdus(self, pdu_list):
|
||||||
"""Returns a new Transaction containing the given PDUs suitable for
|
"""Returns a new Transaction containing the given PDUs suitable for
|
||||||
transmission.
|
transmission.
|
||||||
|
@ -103,8 +103,10 @@ class FederationHandler(BaseHandler):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# We reprocess pdus when we have seen them only as outliers
|
# We reprocess pdus when we have seen them only as outliers
|
||||||
existing = yield self.get_persisted_pdu(
|
existing = yield self.store.get_event(
|
||||||
origin, pdu.event_id, do_auth=False
|
pdu.event_id,
|
||||||
|
allow_none=True,
|
||||||
|
allow_rejected=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# FIXME: Currently we fetch an event again when we already have it
|
# FIXME: Currently we fetch an event again when we already have it
|
||||||
@ -1464,11 +1466,20 @@ class FederationHandler(BaseHandler):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def get_persisted_pdu(self, origin, event_id, do_auth=True):
|
def get_persisted_pdu(self, origin, event_id):
|
||||||
""" Get a PDU from the database with given origin and id.
|
"""Get an event from the database for the given server.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
origin [str]: hostname of server which is requesting the event; we
|
||||||
|
will check that the server is allowed to see it.
|
||||||
|
event_id [str]: id of the event being requested
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Deferred: Results in a `Pdu`.
|
Deferred[EventBase|None]: None if we know nothing about the event;
|
||||||
|
otherwise the (possibly-redacted) event.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
AuthError if the server is not currently in the room
|
||||||
"""
|
"""
|
||||||
event = yield self.store.get_event(
|
event = yield self.store.get_event(
|
||||||
event_id,
|
event_id,
|
||||||
@ -1489,7 +1500,6 @@ class FederationHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if do_auth:
|
|
||||||
in_room = yield self.auth.check_host_in_room(
|
in_room = yield self.auth.check_host_in_room(
|
||||||
event.room_id,
|
event.room_id,
|
||||||
origin
|
origin
|
||||||
@ -1500,9 +1510,7 @@ class FederationHandler(BaseHandler):
|
|||||||
events = yield self._filter_events_for_server(
|
events = yield self._filter_events_for_server(
|
||||||
origin, event.room_id, [event]
|
origin, event.room_id, [event]
|
||||||
)
|
)
|
||||||
|
|
||||||
event = events[0]
|
event = events[0]
|
||||||
|
|
||||||
defer.returnValue(event)
|
defer.returnValue(event)
|
||||||
else:
|
else:
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user