1616
1717import abc
1818import logging
19- from typing import List , Optional , Tuple
20-
21- from twisted .internet import defer
19+ from typing import Dict , List , Optional , Tuple
2220
2321from synapse .storage ._base import SQLBaseStore , db_to_json
2422from synapse .storage .database import DatabasePool
@@ -58,14 +56,16 @@ def get_max_account_data_stream_id(self):
5856 raise NotImplementedError ()
5957
6058 @cached ()
61- def get_account_data_for_user (self , user_id ):
59+ async def get_account_data_for_user (
60+ self , user_id : str
61+ ) -> Tuple [Dict [str , JsonDict ], Dict [str , Dict [str , JsonDict ]]]:
6262 """Get all the client account_data for a user.
6363
6464 Args:
65- user_id(str) : The user to get the account_data for.
65+ user_id: The user to get the account_data for.
6666 Returns:
67- A deferred pair of a dict of global account_data and a dict
68- mapping from room_id string to per room account_data dicts.
67+ A 2-tuple of a dict of global account_data and a dict mapping from
68+ room_id string to per room account_data dicts.
6969 """
7070
7171 def get_account_data_for_user_txn (txn ):
@@ -94,7 +94,7 @@ def get_account_data_for_user_txn(txn):
9494
9595 return global_account_data , by_room
9696
97- return self .db_pool .runInteraction (
97+ return await self .db_pool .runInteraction (
9898 "get_account_data_for_user" , get_account_data_for_user_txn
9999 )
100100
@@ -120,14 +120,16 @@ async def get_global_account_data_by_type_for_user(
120120 return None
121121
122122 @cached (num_args = 2 )
123- def get_account_data_for_room (self , user_id , room_id ):
123+ async def get_account_data_for_room (
124+ self , user_id : str , room_id : str
125+ ) -> Dict [str , JsonDict ]:
124126 """Get all the client account_data for a user for a room.
125127
126128 Args:
127- user_id(str) : The user to get the account_data for.
128- room_id(str) : The room to get the account_data for.
129+ user_id: The user to get the account_data for.
130+ room_id: The room to get the account_data for.
129131 Returns:
130- A deferred dict of the room account_data
132+ A dict of the room account_data
131133 """
132134
133135 def get_account_data_for_room_txn (txn ):
@@ -142,21 +144,22 @@ def get_account_data_for_room_txn(txn):
142144 row ["account_data_type" ]: db_to_json (row ["content" ]) for row in rows
143145 }
144146
145- return self .db_pool .runInteraction (
147+ return await self .db_pool .runInteraction (
146148 "get_account_data_for_room" , get_account_data_for_room_txn
147149 )
148150
149151 @cached (num_args = 3 , max_entries = 5000 )
150- def get_account_data_for_room_and_type (self , user_id , room_id , account_data_type ):
152+ async def get_account_data_for_room_and_type (
153+ self , user_id : str , room_id : str , account_data_type : str
154+ ) -> Optional [JsonDict ]:
151155 """Get the client account_data of given type for a user for a room.
152156
153157 Args:
154- user_id(str) : The user to get the account_data for.
155- room_id(str) : The room to get the account_data for.
156- account_data_type (str) : The account data type to get.
158+ user_id: The user to get the account_data for.
159+ room_id: The room to get the account_data for.
160+ account_data_type: The account data type to get.
157161 Returns:
158- A deferred of the room account_data for that type, or None if
159- there isn't any set.
162+ The room account_data for that type, or None if there isn't any set.
160163 """
161164
162165 def get_account_data_for_room_and_type_txn (txn ):
@@ -174,7 +177,7 @@ def get_account_data_for_room_and_type_txn(txn):
174177
175178 return db_to_json (content_json ) if content_json else None
176179
177- return self .db_pool .runInteraction (
180+ return await self .db_pool .runInteraction (
178181 "get_account_data_for_room_and_type" , get_account_data_for_room_and_type_txn
179182 )
180183
@@ -238,12 +241,14 @@ def get_updated_room_account_data_txn(txn):
238241 "get_updated_room_account_data" , get_updated_room_account_data_txn
239242 )
240243
241- def get_updated_account_data_for_user (self , user_id , stream_id ):
244+ async def get_updated_account_data_for_user (
245+ self , user_id : str , stream_id : int
246+ ) -> Tuple [Dict [str , JsonDict ], Dict [str , Dict [str , JsonDict ]]]:
242247 """Get all the client account_data for a that's changed for a user
243248
244249 Args:
245- user_id(str) : The user to get the account_data for.
246- stream_id(int) : The point in the stream since which to get updates
250+ user_id: The user to get the account_data for.
251+ stream_id: The point in the stream since which to get updates
247252 Returns:
248253 A deferred pair of a dict of global account_data and a dict
249254 mapping from room_id string to per room account_data dicts.
@@ -277,9 +282,9 @@ def get_updated_account_data_for_user_txn(txn):
277282 user_id , int (stream_id )
278283 )
279284 if not changed :
280- return defer . succeed (( {}, {}) )
285+ return ( {}, {})
281286
282- return self .db_pool .runInteraction (
287+ return await self .db_pool .runInteraction (
283288 "get_updated_account_data_for_user" , get_updated_account_data_for_user_txn
284289 )
285290
@@ -416,7 +421,7 @@ async def add_account_data_for_user(
416421
417422 return self ._account_data_id_gen .get_current_token ()
418423
419- def _update_max_stream_id (self , next_id : int ):
424+ async def _update_max_stream_id (self , next_id : int ) -> None :
420425 """Update the max stream_id
421426
422427 Args:
@@ -435,4 +440,4 @@ def _update(txn):
435440 )
436441 txn .execute (update_max_id_sql , (next_id , next_id ))
437442
438- return self .db_pool .runInteraction ("update_account_data_max_stream_id" , _update )
443+ await self .db_pool .runInteraction ("update_account_data_max_stream_id" , _update )
0 commit comments