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

Commit

Permalink
Implement method to get auth_chain from a given event_id
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Nov 7, 2014
1 parent bf6b72e commit 8b0e964
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions synapse/storage/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,41 @@

class EventFederationStore(SQLBaseStore):

def get_auth_chain(self, event_id):
return self.runInteraction(
"get_auth_chain",
self._get_auth_chain_txn,
event_id
)

def _get_auth_chain_txn(self, txn, event_id):
results = set([event_id])

front = set([event_id])
while front:
for ev_id in front:
new_front = set()
auth_ids = self._simple_select_onecol_txn(
txn,
table="event_auth",
keyvalues={
"event_id": ev_id,
},
retcol="auth_id",
)

new_front.update(auth_ids)
front = new_front
new_front.clear()

sql = "SELECT * FROM events WHERE event_id = ?"
rows = []
for ev_id in results:
c = txn.execute(sql, (ev_id,))
rows.extend(self.cursor_to_dict(c))

return self._parse_events_txn(txn, rows)

def get_oldest_events_in_room(self, room_id):
return self.runInteraction(
"get_oldest_events_in_room",
Expand Down

0 comments on commit 8b0e964

Please sign in to comment.