summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2019-01-31 18:21:39 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2019-01-31 18:21:39 +0000
commit3ed3cb43394b41e76f4739f22760c1d8ebfed3c7 (patch)
tree3086e935b3ce52f9b442bcfd68f2a0539a7ee640 /synapse/storage/state.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into anoa/room_upgrad... (diff)
downloadsynapse-3ed3cb43394b41e76f4739f22760c1d8ebfed3c7.tar.xz
New function for getting room's create event
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index c3ab7db7ae..522aaee918 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -24,7 +24,6 @@ import attr
 from twisted.internet import defer
 
 from synapse.api.constants import EventTypes
-from synapse.api.errors import NotFoundError
 from synapse.storage._base import SQLBaseStore
 from synapse.storage.background_updates import BackgroundUpdateStore
 from synapse.storage.engines import PostgresEngine
@@ -428,13 +427,9 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
         """
         # for now we do this by looking at the create event. We may want to cache this
         # more intelligently in future.
-        state_ids = yield self.get_current_state_ids(room_id)
-        create_id = state_ids.get((EventTypes.Create, ""))
-
-        if not create_id:
-            raise NotFoundError("Unknown room %s" % (room_id))
 
-        create_event = yield self.get_event(create_id)
+        # Retrieve the room's create event
+        create_event = yield self.get_create_event_for_room(room_id)
         defer.returnValue(create_event.content.get("room_version", "1"))
 
     @defer.inlineCallbacks
@@ -448,6 +443,22 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
         Returns:
             Deferred[unicode|None]: predecessor room id
         """
+        # Retrieve the room's create event
+        create_event = yield self.get_create_event_for_room(room_id)
+
+        # Return predecessor if present
+        defer.returnValue(create_event.content.get("predecessor", None))
+
+    @defer.inlineCallbacks
+    def get_create_event_for_room(self, room_id):
+        """Get the create state event for a room.
+
+        Args:
+            room_id (str)
+
+        Returns:
+            Deferred[EventBase|None]: The room creation event. None if can not be found
+        """
         state_ids = yield self.get_current_state_ids(room_id)
         create_id = state_ids.get((EventTypes.Create, ""))
 
@@ -455,11 +466,9 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
         if not create_id:
             defer.returnValue(None)
 
-        # Retrieve the room's create event
+        # Retrieve the room's create event and return
         create_event = yield self.get_event(create_id)
-
-        # Return predecessor if present
-        defer.returnValue(create_event.content.get("predecessor", None))
+        defer.returnValue(create_event)
 
     @cached(max_entries=100000, iterable=True)
     def get_current_state_ids(self, room_id):