14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
import logging
17
- from http import HTTPStatus
18
17
from typing import (
19
18
TYPE_CHECKING ,
20
19
Any ,
@@ -921,12 +920,8 @@ class DeviceListWorkerUpdater:
921
920
def __init__ (self , hs : "HomeServer" ):
922
921
from synapse .replication .http .devices import (
923
922
ReplicationMultiUserDevicesResyncRestServlet ,
924
- ReplicationUserDevicesResyncRestServlet ,
925
923
)
926
924
927
- self ._user_device_resync_client = (
928
- ReplicationUserDevicesResyncRestServlet .make_client (hs )
929
- )
930
925
self ._multi_user_device_resync_client = (
931
926
ReplicationMultiUserDevicesResyncRestServlet .make_client (hs )
932
927
)
@@ -948,37 +943,7 @@ async def multi_user_device_resync(
948
943
# Shortcut empty requests
949
944
return {}
950
945
951
- try :
952
- return await self ._multi_user_device_resync_client (user_ids = user_ids )
953
- except SynapseError as err :
954
- if not (
955
- err .code == HTTPStatus .NOT_FOUND and err .errcode == Codes .UNRECOGNIZED
956
- ):
957
- raise
958
-
959
- # Fall back to single requests
960
- result : Dict [str , Optional [JsonDict ]] = {}
961
- for user_id in user_ids :
962
- result [user_id ] = await self ._user_device_resync_client (user_id = user_id )
963
- return result
964
-
965
- async def user_device_resync (
966
- self , user_id : str , mark_failed_as_stale : bool = True
967
- ) -> Optional [JsonDict ]:
968
- """Fetches all devices for a user and updates the device cache with them.
969
-
970
- Args:
971
- user_id: The user's id whose device_list will be updated.
972
- mark_failed_as_stale: Whether to mark the user's device list as stale
973
- if the attempt to resync failed.
974
- Returns:
975
- A dict with device info as under the "devices" in the result of this
976
- request:
977
- https://matrix.org/docs/spec/server_server/r0.1.2#get-matrix-federation-v1-user-devices-userid
978
- None when we weren't able to fetch the device info for some reason,
979
- e.g. due to a connection problem.
980
- """
981
- return (await self .multi_user_device_resync ([user_id ]))[user_id ]
946
+ return await self ._multi_user_device_resync_client (user_ids = user_ids )
982
947
983
948
984
949
class DeviceListUpdater (DeviceListWorkerUpdater ):
@@ -1131,7 +1096,7 @@ async def _handle_device_updates(self, user_id: str) -> None:
1131
1096
)
1132
1097
1133
1098
if resync :
1134
- await self .user_device_resync ( user_id )
1099
+ await self .multi_user_device_resync ([ user_id ] )
1135
1100
else :
1136
1101
# Simply update the single device, since we know that is the only
1137
1102
# change (because of the single prev_id matching the current cache)
@@ -1198,10 +1163,9 @@ async def _maybe_retry_device_resync(self) -> None:
1198
1163
for user_id in need_resync :
1199
1164
try :
1200
1165
# Try to resync the current user's devices list.
1201
- result = await self .user_device_resync (
1202
- user_id = user_id ,
1203
- mark_failed_as_stale = False ,
1204
- )
1166
+ result = (await self .multi_user_device_resync ([user_id ], False ))[
1167
+ user_id
1168
+ ]
1205
1169
1206
1170
# user_device_resync only returns a result if it managed to
1207
1171
# successfully resync and update the database. Updating the table
@@ -1260,18 +1224,6 @@ async def multi_user_device_resync(
1260
1224
1261
1225
return result
1262
1226
1263
- async def user_device_resync (
1264
- self , user_id : str , mark_failed_as_stale : bool = True
1265
- ) -> Optional [JsonDict ]:
1266
- result , failed = await self ._user_device_resync_returning_failed (user_id )
1267
-
1268
- if failed and mark_failed_as_stale :
1269
- # Mark the remote user's device list as stale so we know we need to retry
1270
- # it later.
1271
- await self .store .mark_remote_users_device_caches_as_stale ((user_id ,))
1272
-
1273
- return result
1274
-
1275
1227
async def _user_device_resync_returning_failed (
1276
1228
self , user_id : str
1277
1229
) -> Tuple [Optional [JsonDict ], bool ]:
0 commit comments