New function for getting room's create event

This commit is contained in:
Andrew Morgan 2019-01-31 18:21:39 +00:00
parent bbb97a35fd
commit 3ed3cb4339
2 changed files with 21 additions and 18 deletions

View File

@ -266,13 +266,7 @@ class RoomCreationHandler(BaseHandler):
# Check if old room was non-federatable
# Get old room's create event
old_room_create_event_ids = yield self.store.get_filtered_current_state_ids(
old_room_id, StateFilter.from_types(((EventTypes.Create, ""),)),
)
old_room_create_event_dict = yield self.store.get_events(
old_room_create_event_ids.values(),
)
old_room_create_event = list(old_room_create_event_dict.values())[0]
old_room_create_event = yield self.store.get_create_event_for_room(old_room_id)
# Check if the create event specified a non-federatable room
if not old_room_create_event.content.get("m.federate", True):

View File

@ -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):