summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2019-01-22 11:12:48 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2019-01-22 12:00:41 +0000
commitc9bfb058d85f6205fada062c78a4d1eca119417c (patch)
treec3b6c29841ca3b82bfec6aa3dd3155531dc77537 /synapse/storage/state.py
parentAdd changelog (diff)
downloadsynapse-c9bfb058d85f6205fada062c78a4d1eca119417c.tar.xz
Fix a bug with single-room search searching all rooms
* Create a new method for getting predecessor rooms
* Remove formatting change
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index 49b3ff4a71..b064671851 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -437,6 +437,34 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
         create_event = yield self.get_event(create_id)
         defer.returnValue(create_event.content.get("room_version", "1"))
 
+    @defer.inlineCallbacks
+    def get_room_predecessor(self, room_id):
+        """Get the predecessor room of an upgraded room if one exists.
+        Otherwise return None.
+
+        Args:
+            room_id (str)
+
+        Returns:
+            Deferred[str]: predecessor room id
+        """
+
+        state_ids = yield self.get_current_state_ids(room_id)
+        create_id = state_ids.get((EventTypes.Create, ""))
+
+        # If we can't find the create event, assume we've hit a dead end
+        if not create_id:
+            return None
+
+        # Retrieve the room's create event
+        create_event = yield self.get_event(create_id)
+
+        if not create_event:
+            return None
+
+        # Return predecessor if present
+        return create_event.content.get("predecessor", None)
+
     @cached(max_entries=100000, iterable=True)
     def get_current_state_ids(self, room_id):
         """Get the current state event ids for a room based on the
@@ -448,7 +476,6 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
         Returns:
             deferred: dict of (type, state_key) -> event_id
         """
-
         def _get_current_state_ids_txn(txn):
             txn.execute(
                 """SELECT type, state_key, event_id FROM current_state_events