summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-11-07 10:42:31 +0000
committerErik Johnston <erik@matrix.org>2014-11-07 10:53:38 +0000
commit8b0e96474b3a18866f28f112de7e56979b401768 (patch)
tree89534e2848670824e9cdbde3515f45faa48eddea /synapse
parentStart implementing auth chains (diff)
downloadsynapse-8b0e96474b3a18866f28f112de7e56979b401768.tar.xz
Implement method to get auth_chain from a given event_id
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/event_federation.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/synapse/storage/event_federation.py b/synapse/storage/event_federation.py
index 86c68ebf87..7140ea3d57 100644
--- a/synapse/storage/event_federation.py
+++ b/synapse/storage/event_federation.py
@@ -24,6 +24,41 @@ logger = logging.getLogger(__name__)
 
 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",