summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-12 14:14:58 +0100
committerErik Johnston <erik@matrix.org>2015-05-12 14:14:58 +0100
commit74850d7f75f64e537c3db36103107aece0fdf47f (patch)
treecee904986dda9528a9c73801cfe1d3191f647e58
parents/backfil/backfill/ (diff)
downloadsynapse-74850d7f75f64e537c3db36103107aece0fdf47f.tar.xz
Do state groups persistence /after/ checking if we have already persisted the event
-rw-r--r--synapse/storage/events.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 38395c66ab..a66e84b344 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -135,19 +135,17 @@ class EventsStore(SQLBaseStore):
         outlier = event.internal_metadata.is_outlier()
 
         if not outlier:
-            self._store_state_groups_txn(txn, event, context)
-
             self._update_min_depth_for_room_txn(
                 txn,
                 event.room_id,
                 event.depth
             )
 
-        have_persisted = self._simple_select_one_onecol_txn(
+        have_persisted = self._simple_select_one_txn(
             txn,
-            table="event_json",
+            table="events",
             keyvalues={"event_id": event.event_id},
-            retcol="event_id",
+            retcols=["event_id", "outlier"],
             allow_none=True,
         )
 
@@ -162,7 +160,9 @@ class EventsStore(SQLBaseStore):
         # if we are persisting an event that we had persisted as an outlier,
         # but is no longer one.
         if have_persisted:
-            if not outlier:
+            if not outlier and have_persisted["outlier"]:
+                self._store_state_groups_txn(txn, event, context)
+
                 sql = (
                     "UPDATE event_json SET internal_metadata = ?"
                     " WHERE event_id = ?"
@@ -182,6 +182,9 @@ class EventsStore(SQLBaseStore):
                 )
             return
 
+        if not outlier:
+            self._store_state_groups_txn(txn, event, context)
+
         self._handle_prev_events(
             txn,
             outlier=outlier,