summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-17 23:37:08 +0000
committerErik Johnston <erik@matrix.org>2014-12-17 23:37:08 +0000
commitf3788e3c7881de25c7d699bb9940b3cbd4dc3682 (patch)
treebfb533714a3c152cebf649612cd9b007ea048352 /synapse
parentUse _get_events_txn instead of _parse_events_txn (diff)
downloadsynapse-f3788e3c7881de25c7d699bb9940b3cbd4dc3682.tar.xz
Test some ideas that might help performance a bit
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/federation.py4
-rw-r--r--synapse/storage/_base.py34
-rw-r--r--synapse/storage/roommember.py8
-rw-r--r--synapse/storage/state.py9
4 files changed, 32 insertions, 23 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index b76dcd98e2..2f6036145c 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -91,7 +91,7 @@ class FederationHandler(BaseHandler):
 
         yield run_on_reactor()
 
-        yield self.replication_layer.send_pdu(event, destinations)
+        self.replication_layer.send_pdu(event, destinations)
 
     @log_function
     @defer.inlineCallbacks
@@ -527,7 +527,7 @@ class FederationHandler(BaseHandler):
             event.signatures,
         )
 
-        yield self.replication_layer.send_pdu(new_pdu, destinations)
+        self.replication_layer.send_pdu(new_pdu, destinations)
 
         state_ids = [e.event_id for e in context.current_state.values()]
         auth_chain = yield self.store.get_auth_chain(set(
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index e0d97f440b..a6e2e0e2ef 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -440,14 +440,29 @@ class SQLBaseStore(object):
         )
 
     def _get_events_txn(self, txn, event_ids):
-        events = []
-        for e_id in event_ids:
-            ev = self._get_event_txn(txn, e_id)
+	if not event_ids:
+		return []
 
-            if ev:
-                events.append(ev)
+	if len(event_ids) > 50:
+		events = []
+		n = 50
+		for e_ids in [event_ids[i:i + n] for i in range(0, len(event_ids), n)]:
+			events.extend(self._get_events_txn(txn, e_ids))
+		return events
 
-        return events
+        where_clause = " OR ".join(["e.event_id = ?" for _ in event_ids])
+
+        sql = (
+            "SELECT internal_metadata, json, r.event_id FROM event_json as e "
+            "LEFT JOIN redactions as r ON e.event_id = r.redacts "
+            "WHERE %s"
+        ) % (where_clause,)
+
+        txn.execute(sql, event_ids)
+
+        res = txn.fetchall()
+
+        return [self._get_event_from_row_txn(txn, *r) for r in res]
 
     def _get_event_txn(self, txn, event_id, check_redacted=True,
                        get_prev_content=True):
@@ -467,6 +482,13 @@ class SQLBaseStore(object):
 
         internal_metadata, js, redacted = res
 
+	return self._get_event_from_row_txn(
+		txn, internal_metadata, js, redacted, check_redacted=check_redacted,
+		get_prev_content=get_prev_content,
+	)
+
+    def _get_event_from_row_txn(self, txn, internal_metadata, js, redacted,
+				check_redacted=True, get_prev_content=True):
         d = json.loads(js)
         internal_metadata = json.loads(internal_metadata)
 
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 05b275663e..4e416c50b1 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -183,20 +183,14 @@ class RoomMemberStore(SQLBaseStore):
         )
 
     def _get_members_query_txn(self, txn, where_clause, where_values):
-        del_sql = (
-            "SELECT event_id FROM redactions WHERE redacts = e.event_id "
-            "LIMIT 1"
-        )
-
         sql = (
-            "SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
+            "SELECT e.* FROM events as e "
             "INNER JOIN room_memberships as m "
             "ON e.event_id = m.event_id "
             "INNER JOIN current_state_events as c "
             "ON m.event_id = c.event_id "
             "WHERE %(where)s "
         ) % {
-            "redacted": del_sql,
             "where": where_clause,
         }
 
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index afe3e5edea..ab80909712 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -62,14 +62,7 @@ class StateStore(SQLBaseStore):
                     keyvalues={"state_group": group},
                     retcol="event_id",
                 )
-                state = []
-                for state_id in state_ids:
-                    s = self._get_events_txn(
-                        txn,
-                        [state_id],
-                    )
-                    if s:
-                        state.extend(s)
+                state = self._get_events_txn(txn, state_ids)
 
                 res[group] = state