summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-06-01 17:13:37 +0100
committerErik Johnston <erik@matrix.org>2018-06-01 17:13:37 +0100
commit2908104ed6bd59c2a9089a0b02946e38abc66a25 (patch)
tree0c497ed247eca911d4fe5682100318af627f95a9
parentfixu[p (diff)
downloadsynapse-2908104ed6bd59c2a9089a0b02946e38abc66a25.tar.xz
Speed things up a bit
-rw-r--r--synapse/storage/events.py60
1 files changed, 43 insertions, 17 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 72a35679db..2427d3b4b2 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -1468,6 +1468,19 @@ class EventsStore(EventsWorkerStore):
                 retcol="COALESCE(MAX(topological_ordering), 0)",
             )
             new_topo += 1
+
+            # We need to now update the database with any new edges between chunks
+            current_prev_ids = set()
+
+            current_forward_ids = self._simple_select_onecol_txn(
+                txn,
+                table="chunk_graph",
+                keyvalues={
+                    "prev_id": chunk_id,
+                },
+                retcol="chunk_id",
+            )
+
         # If there is only one forward chunk and only one sibling event (which
         # would be the given event), then this satisfies condition two.
         elif len(forward_chunk_ids) == 1 and len(sibling_events) == 1:
@@ -1484,6 +1497,18 @@ class EventsStore(EventsWorkerStore):
                 retcol="COALESCE(MIN(topological_ordering), 0)",
             )
             new_topo -= 1
+
+            # We need to now update the database with any new edges between chunks
+            current_prev_ids = self._simple_select_onecol_txn(
+                txn,
+                table="chunk_graph",
+                keyvalues={
+                    "chunk_id": chunk_id,
+                },
+                retcol="prev_id",
+            )
+
+            current_forward_ids = set()
         else:
             chunk_id = self._chunk_id_gen.get_next()
             new_topo = 0
@@ -1492,24 +1517,24 @@ class EventsStore(EventsWorkerStore):
             # ChunkDBOrderedListStore about that.
             table.add_node(chunk_id)
 
-        # We need to now update the database with any new edges between chunks
-        current_prev_ids = self._simple_select_onecol_txn(
-            txn,
-            table="chunk_graph",
-            keyvalues={
-                "chunk_id": chunk_id,
-            },
-            retcol="prev_id",
-        )
+            # We need to now update the database with any new edges between chunks
+            current_prev_ids = self._simple_select_onecol_txn(
+                txn,
+                table="chunk_graph",
+                keyvalues={
+                    "chunk_id": chunk_id,
+                },
+                retcol="prev_id",
+            )
 
-        current_forward_ids = self._simple_select_onecol_txn(
-            txn,
-            table="chunk_graph",
-            keyvalues={
-                "prev_id": chunk_id,
-            },
-            retcol="chunk_id",
-        )
+            current_forward_ids = self._simple_select_onecol_txn(
+                txn,
+                table="chunk_graph",
+                keyvalues={
+                    "prev_id": chunk_id,
+                },
+                retcol="chunk_id",
+            )
 
         prev_chunk_ids = set(
             pid for pid in prev_chunk_ids
@@ -1538,6 +1563,7 @@ class EventsStore(EventsWorkerStore):
                 INSERT INTO chunk_backwards_extremities (chunk_id, event_id)
                 SELECT ?, ? WHERE NOT EXISTS (
                     SELECT event_id FROM events WHERE event_id = ?
+                    AND NOT outlier
                 )
             """, [(chunk_id, eid, eid) for eid in prev_event_ids])