@@ -58,10 +58,8 @@ def __init__(self, database: DatabasePool, db_conn, hs):
58
58
59
59
async def get_room_version (self , room_id : str ) -> RoomVersion :
60
60
"""Get the room_version of a given room
61
-
62
61
Raises:
63
62
NotFoundError: if the room is unknown
64
-
65
63
UnsupportedRoomVersionError: if the room uses an unknown room version.
66
64
Typically this happens if support for the room's version has been
67
65
removed from Synapse.
@@ -76,14 +74,11 @@ def get_room_version_txn(
76
74
self , txn : LoggingTransaction , room_id : str
77
75
) -> RoomVersion :
78
76
"""Get the room_version of a given room
79
-
80
77
Args:
81
78
txn: Transaction object
82
79
room_id: The room_id of the room you are trying to get the version for
83
-
84
80
Raises:
85
81
NotFoundError: if the room is unknown
86
-
87
82
UnsupportedRoomVersionError: if the room uses an unknown room version.
88
83
Typically this happens if support for the room's version has been
89
84
removed from Synapse.
@@ -102,7 +97,6 @@ def get_room_version_txn(
102
97
@cached (max_entries = 10000 )
103
98
async def get_room_version_id (self , room_id : str ) -> str :
104
99
"""Get the room_version of a given room
105
-
106
100
Raises:
107
101
NotFoundError: if the room is unknown
108
102
"""
@@ -114,11 +108,9 @@ async def get_room_version_id(self, room_id: str) -> str:
114
108
115
109
def get_room_version_id_txn (self , txn : LoggingTransaction , room_id : str ) -> str :
116
110
"""Get the room_version of a given room
117
-
118
111
Args:
119
112
txn: Transaction object
120
113
room_id: The room_id of the room you are trying to get the version for
121
-
122
114
Raises:
123
115
NotFoundError: if the room is unknown
124
116
"""
@@ -138,12 +130,10 @@ def get_room_version_id_txn(self, txn: LoggingTransaction, room_id: str) -> str:
138
130
allow_none = True ,
139
131
)
140
132
141
- if room_version is not None :
142
- return room_version
133
+ if room_version is None :
134
+ raise NotFoundError ( "Could not room_version for %s" % ( room_id ,))
143
135
144
- # Retrieve the room's create event
145
- create_event = self .get_create_event_for_room_txn (txn , room_id )
146
- return create_event .content .get ("room_version" , "1" )
136
+ return room_version
147
137
148
138
async def get_room_predecessor (self , room_id : str ) -> Optional [dict ]:
149
139
"""Get the predecessor of an upgraded room if it exists.
@@ -188,37 +178,15 @@ async def get_create_event_for_room(self, room_id: str) -> EventBase:
188
178
Raises:
189
179
NotFoundError if the room is unknown
190
180
"""
191
- return await self .db_pool .runInteraction (
192
- "get_create_event_for_room_txn" ,
193
- self .get_create_event_for_room_txn ,
194
- room_id ,
195
- )
196
-
197
- def get_create_event_for_room_txn (
198
- self , txn : LoggingTransaction , room_id : str
199
- ) -> EventBase :
200
- """Get the create state event for a room.
201
-
202
- Args:
203
- txn: Transaction object
204
- room_id: The room ID.
205
-
206
- Returns:
207
- The room creation event.
208
-
209
- Raises:
210
- NotFoundError if the room is unknown
211
- """
212
-
213
- state_ids = self .get_current_state_ids_txn (txn , room_id )
181
+ state_ids = await self .get_current_state_ids (room_id )
214
182
create_id = state_ids .get ((EventTypes .Create , "" ))
215
183
216
184
# If we can't find the create event, assume we've hit a dead end
217
185
if not create_id :
218
186
raise NotFoundError ("Unknown room %s" % (room_id ,))
219
187
220
188
# Retrieve the room's create event and return
221
- create_event = self .get_event_txn ( txn , create_id )
189
+ create_event = await self .get_event ( create_id )
222
190
return create_event
223
191
224
192
@cached (max_entries = 100000 , iterable = True )
@@ -233,35 +201,20 @@ async def get_current_state_ids(self, room_id: str) -> StateMap[str]:
233
201
The current state of the room.
234
202
"""
235
203
236
- return await self .db_pool .runInteraction (
237
- "get_current_state_ids_txn" ,
238
- self .get_current_state_ids_txn ,
239
- room_id ,
240
- )
241
-
242
- def get_current_state_ids_txn (
243
- self , txn : LoggingTransaction , room_id : str
244
- ) -> StateMap [str ]:
245
- """Get the current state event ids for a room based on the
246
- current_state_events table.
204
+ def _get_current_state_ids_txn (txn ):
205
+ txn .execute (
206
+ """SELECT type, state_key, event_id FROM current_state_events
207
+ WHERE room_id = ?
208
+ """ ,
209
+ (room_id ,),
210
+ )
247
211
248
- Args:
249
- txn: Transaction object
250
- room_id: The room to get the state IDs of.
212
+ return {(intern_string (r [0 ]), intern_string (r [1 ])): r [2 ] for r in txn }
251
213
252
- Returns:
253
- The current state of the room.
254
- """
255
-
256
- txn .execute (
257
- """SELECT type, state_key, event_id FROM current_state_events
258
- WHERE room_id = ?
259
- """ ,
260
- (room_id ,),
214
+ return await self .db_pool .runInteraction (
215
+ "get_current_state_ids" , _get_current_state_ids_txn
261
216
)
262
217
263
- return {(intern_string (r [0 ]), intern_string (r [1 ])): r [2 ] for r in txn }
264
-
265
218
# FIXME: how should this be cached?
266
219
async def get_filtered_current_state_ids (
267
220
self , room_id : str , state_filter : Optional [StateFilter ] = None
0 commit comments