summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-01 16:21:17 +0000
committerErik Johnston <erik@matrix.org>2014-12-01 16:22:07 +0000
commitec2b5d8c284451179c0f7b72c46dda0dd81f6f5f (patch)
tree558ddd1adeb905df498b4fbafba32cd9590a792a /synapse/storage/_base.py
parentre-add OSX troubleshooting instructions (not sure how they got lost) (diff)
downloadsynapse-ec2b5d8c284451179c0f7b72c46dda0dd81f6f5f.tar.xz
Store full JSON of events in db
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r--synapse/storage/_base.py77
1 files changed, 21 insertions, 56 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 4881f03368..bb61c20150 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -479,66 +479,30 @@ class SQLBaseStore(object):
         )
 
     def _parse_events_txn(self, txn, rows):
-        events = [self._parse_event_from_row(r) for r in rows]
-
-        select_event_sql = (
-            "SELECT * FROM events WHERE event_id = ? ORDER BY rowid asc"
-        )
-
-        for i, ev in enumerate(events):
-            signatures = self._get_event_signatures_txn(
-                txn, ev.event_id,
+        event_ids = [r["event_id"] for r in rows]
+
+        events = []
+        for event_id in event_ids:
+            js = self._simple_select_one_onecol_txn(
+                txn,
+                table="event_json",
+                keyvalues={"event_id": event_id},
+                retcol="json",
+                allow_none=True,
             )
 
-            ev.signatures = {
-                n: {
-                    k: encode_base64(v) for k, v in s.items()
-                }
-                for n, s in signatures.items()
-            }
-
-            hashes = self._get_event_content_hashes_txn(
-                txn, ev.event_id,
-            )
+            if not js:
+                # FIXME (erikj): What should we actually do here?
+                continue
 
-            ev.hashes = {
-                k: encode_base64(v) for k, v in hashes.items()
-            }
-
-            prevs = self._get_prev_events_and_state(txn, ev.event_id)
-
-            ev.prev_events = [
-                (e_id, h)
-                for e_id, h, is_state in prevs
-                if is_state == 0
-            ]
-
-            ev.auth_events = self._get_auth_events(txn, ev.event_id)
-
-            if hasattr(ev, "state_key"):
-                ev.prev_state = [
-                    (e_id, h)
-                    for e_id, h, is_state in prevs
-                    if is_state == 1
-                ]
-
-                if hasattr(ev, "replaces_state"):
-                    # Load previous state_content.
-                    # FIXME (erikj): Handle multiple prev_states.
-                    cursor = txn.execute(
-                        select_event_sql,
-                        (ev.replaces_state,)
-                    )
-                    prevs = self.cursor_to_dict(cursor)
-                    if prevs:
-                        prev = self._parse_event_from_row(prevs[0])
-                        ev.prev_content = prev.content
+            d = json.loads(js)
 
-            if not hasattr(ev, "redacted"):
-                logger.debug("Doesn't have redacted key: %s", ev)
-                ev.redacted = self._has_been_redacted_txn(txn, ev)
+            ev = self.event_factory.create_event(
+                etype=d["type"],
+                **d
+            )
 
-            if ev.redacted:
+            if hasattr(ev, "redacted") and ev.redacted:
                 # Get the redaction event.
                 select_event_sql = "SELECT * FROM events WHERE event_id = ?"
                 txn.execute(select_event_sql, (ev.redacted,))
@@ -549,9 +513,10 @@ class SQLBaseStore(object):
 
                 if del_evs:
                     ev = prune_event(ev)
-                    events[i] = ev
                     ev.redacted_because = del_evs[0]
 
+            events.append(ev)
+
         return events
 
     def _has_been_redacted_txn(self, txn, event):