mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:06:07 -04:00
Avoid extra db lookups
Since we're about to look up the events themselves anyway, we can skip the extra db queries here.
This commit is contained in:
parent
0a65450d04
commit
14fa9d4d92
3 changed files with 26 additions and 62 deletions
|
@ -1350,7 +1350,9 @@ class FederationHandler(BaseHandler):
|
|||
"""Returns the state at the event. i.e. not including said event.
|
||||
"""
|
||||
|
||||
yield self._verify_events_in_room([event_id], room_id)
|
||||
event = yield self.store.get_event(
|
||||
event_id, allow_none=False, check_room_id=room_id,
|
||||
)
|
||||
|
||||
state_groups = yield self.store.get_state_groups(
|
||||
room_id, [event_id]
|
||||
|
@ -1362,8 +1364,7 @@ class FederationHandler(BaseHandler):
|
|||
(e.type, e.state_key): e for e in state
|
||||
}
|
||||
|
||||
event = yield self.store.get_event(event_id)
|
||||
if event and event.is_state():
|
||||
if event.is_state():
|
||||
# Get previous state
|
||||
if "replaces_state" in event.unsigned:
|
||||
prev_id = event.unsigned["replaces_state"]
|
||||
|
@ -1394,8 +1395,9 @@ class FederationHandler(BaseHandler):
|
|||
def get_state_ids_for_pdu(self, room_id, event_id):
|
||||
"""Returns the state at the event. i.e. not including said event.
|
||||
"""
|
||||
|
||||
yield self._verify_events_in_room([event_id], room_id)
|
||||
event = yield self.store.get_event(
|
||||
event_id, allow_none=False, check_room_id=room_id,
|
||||
)
|
||||
|
||||
state_groups = yield self.store.get_state_groups_ids(
|
||||
room_id, [event_id]
|
||||
|
@ -1405,8 +1407,7 @@ class FederationHandler(BaseHandler):
|
|||
_, state = state_groups.items().pop()
|
||||
results = state
|
||||
|
||||
event = yield self.store.get_event(event_id)
|
||||
if event and event.is_state():
|
||||
if event.is_state():
|
||||
# Get previous state
|
||||
if "replaces_state" in event.unsigned:
|
||||
prev_id = event.unsigned["replaces_state"]
|
||||
|
@ -1426,8 +1427,6 @@ class FederationHandler(BaseHandler):
|
|||
if not in_room:
|
||||
raise AuthError(403, "Host not in room.")
|
||||
|
||||
yield self._verify_events_in_room(pdu_list, room_id)
|
||||
|
||||
events = yield self.store.get_backfill_events(
|
||||
room_id,
|
||||
pdu_list,
|
||||
|
@ -1723,7 +1722,9 @@ class FederationHandler(BaseHandler):
|
|||
if not in_room:
|
||||
raise AuthError(403, "Host not in room.")
|
||||
|
||||
yield self._verify_events_in_room([event_id], room_id)
|
||||
event = yield self.store.get_event(
|
||||
event_id, allow_none=False, check_room_id=room_id
|
||||
)
|
||||
|
||||
# Just go through and process each event in `remote_auth_chain`. We
|
||||
# don't want to fall into the trap of `missing` being wrong.
|
||||
|
@ -1734,7 +1735,6 @@ class FederationHandler(BaseHandler):
|
|||
pass
|
||||
|
||||
# Now get the current auth_chain for the event.
|
||||
event = yield self.store.get_event(event_id)
|
||||
local_auth_chain = yield self.store.get_auth_chain(
|
||||
[auth_id for auth_id, _ in event.auth_events],
|
||||
include_given=True
|
||||
|
@ -2385,19 +2385,3 @@ class FederationHandler(BaseHandler):
|
|||
)
|
||||
if "valid" not in response or not response["valid"]:
|
||||
raise AuthError(403, "Third party certificate was invalid")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _verify_events_in_room(self, pdu_ids, room_id):
|
||||
"""Checks whether the given PDU IDs are in the given room or not.
|
||||
|
||||
Args:
|
||||
pdu_ids (list): list of PDU IDs
|
||||
room_id (str): the room ID that the PDUs should be in
|
||||
|
||||
Raises:
|
||||
AuthError: if one or more of the PDUs does not belong to the
|
||||
given room.
|
||||
"""
|
||||
room_ids = yield self.store.get_room_ids_for_events(pdu_ids)
|
||||
if len(room_ids) != 1 or room_ids[0] != room_id:
|
||||
raise AuthError(403, "Events must belong to the given room")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue