Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add rooms.room_version column #6729

Merged
merged 13 commits into from
Jan 27, 2020
Merged
31 changes: 19 additions & 12 deletions synapse/storage/data_stores/main/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,31 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
def __init__(self, database: Database, db_conn, hs):
super(StateGroupWorkerStore, self).__init__(database, db_conn, hs)

@defer.inlineCallbacks
def get_room_version(self, room_id):
@cached(max_entries=10000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh did I miss the memo where async functions can be cached?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, turns out that somewhere in the depths the cache descriptor calls run_in_background on the cahced function

async def get_room_version(self, room_id: str) -> str:
"""Get the room_version of a given room

Args:
room_id (str)

Returns:
Deferred[str]

Raises:
NotFoundError if the room is unknown
NotFoundError: if the room is unknown
"""
# for now we do this by looking at the create event. We may want to cache this
# more intelligently in future.

# First we try looking up room version from the database, but for old
# rooms we might not have added the room version to it yet so we fall
# back to previous behaviour and look in current state events.

version = await self.db.simple_select_one_onecol(
table="rooms",
keyvalues={"room_id": room_id},
retcol="room_version",
desc="get_room_version",
allow_none=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be needed? the row should be there whether or not the version is updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 10000000% comfortable asserting that we definitely do have a row in rooms for every single room right now

)

if version:
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
return version

# Retrieve the room's create event
create_event = yield self.get_create_event_for_room(room_id)
create_event = await self.get_create_event_for_room(room_id)
return create_event.content.get("room_version", "1")

@defer.inlineCallbacks
Expand Down