|
|
@ -14,7 +14,6 @@ |
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
# limitations under the License. |
|
|
|
# limitations under the License. |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
from http import HTTPStatus |
|
|
|
|
|
|
|
from typing import ( |
|
|
|
from typing import ( |
|
|
|
TYPE_CHECKING, |
|
|
|
TYPE_CHECKING, |
|
|
|
Any, |
|
|
|
Any, |
|
|
@ -921,12 +920,8 @@ class DeviceListWorkerUpdater: |
|
|
|
def __init__(self, hs: "HomeServer"): |
|
|
|
def __init__(self, hs: "HomeServer"): |
|
|
|
from synapse.replication.http.devices import ( |
|
|
|
from synapse.replication.http.devices import ( |
|
|
|
ReplicationMultiUserDevicesResyncRestServlet, |
|
|
|
ReplicationMultiUserDevicesResyncRestServlet, |
|
|
|
ReplicationUserDevicesResyncRestServlet, |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
self._user_device_resync_client = ( |
|
|
|
|
|
|
|
ReplicationUserDevicesResyncRestServlet.make_client(hs) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
self._multi_user_device_resync_client = ( |
|
|
|
self._multi_user_device_resync_client = ( |
|
|
|
ReplicationMultiUserDevicesResyncRestServlet.make_client(hs) |
|
|
|
ReplicationMultiUserDevicesResyncRestServlet.make_client(hs) |
|
|
|
) |
|
|
|
) |
|
|
@ -948,37 +943,7 @@ class DeviceListWorkerUpdater: |
|
|
|
# Shortcut empty requests |
|
|
|
# Shortcut empty requests |
|
|
|
return {} |
|
|
|
return {} |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
return await self._multi_user_device_resync_client(user_ids=user_ids) |
|
|
|
return await self._multi_user_device_resync_client(user_ids=user_ids) |
|
|
|
except SynapseError as err: |
|
|
|
|
|
|
|
if not ( |
|
|
|
|
|
|
|
err.code == HTTPStatus.NOT_FOUND and err.errcode == Codes.UNRECOGNIZED |
|
|
|
|
|
|
|
): |
|
|
|
|
|
|
|
raise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fall back to single requests |
|
|
|
|
|
|
|
result: Dict[str, Optional[JsonDict]] = {} |
|
|
|
|
|
|
|
for user_id in user_ids: |
|
|
|
|
|
|
|
result[user_id] = await self._user_device_resync_client(user_id=user_id) |
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def user_device_resync( |
|
|
|
|
|
|
|
self, user_id: str, mark_failed_as_stale: bool = True |
|
|
|
|
|
|
|
) -> Optional[JsonDict]: |
|
|
|
|
|
|
|
"""Fetches all devices for a user and updates the device cache with them. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
|
|
user_id: The user's id whose device_list will be updated. |
|
|
|
|
|
|
|
mark_failed_as_stale: Whether to mark the user's device list as stale |
|
|
|
|
|
|
|
if the attempt to resync failed. |
|
|
|
|
|
|
|
Returns: |
|
|
|
|
|
|
|
A dict with device info as under the "devices" in the result of this |
|
|
|
|
|
|
|
request: |
|
|
|
|
|
|
|
https://matrix.org/docs/spec/server_server/r0.1.2#get-matrix-federation-v1-user-devices-userid |
|
|
|
|
|
|
|
None when we weren't able to fetch the device info for some reason, |
|
|
|
|
|
|
|
e.g. due to a connection problem. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
return (await self.multi_user_device_resync([user_id]))[user_id] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceListUpdater(DeviceListWorkerUpdater): |
|
|
|
class DeviceListUpdater(DeviceListWorkerUpdater): |
|
|
@ -1131,7 +1096,7 @@ class DeviceListUpdater(DeviceListWorkerUpdater): |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if resync: |
|
|
|
if resync: |
|
|
|
await self.user_device_resync(user_id) |
|
|
|
await self.multi_user_device_resync([user_id]) |
|
|
|
else: |
|
|
|
else: |
|
|
|
# Simply update the single device, since we know that is the only |
|
|
|
# Simply update the single device, since we know that is the only |
|
|
|
# change (because of the single prev_id matching the current cache) |
|
|
|
# change (because of the single prev_id matching the current cache) |
|
|
@ -1198,10 +1163,9 @@ class DeviceListUpdater(DeviceListWorkerUpdater): |
|
|
|
for user_id in need_resync: |
|
|
|
for user_id in need_resync: |
|
|
|
try: |
|
|
|
try: |
|
|
|
# Try to resync the current user's devices list. |
|
|
|
# Try to resync the current user's devices list. |
|
|
|
result = await self.user_device_resync( |
|
|
|
result = (await self.multi_user_device_resync([user_id], False))[ |
|
|
|
user_id=user_id, |
|
|
|
user_id |
|
|
|
mark_failed_as_stale=False, |
|
|
|
] |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# user_device_resync only returns a result if it managed to |
|
|
|
# user_device_resync only returns a result if it managed to |
|
|
|
# successfully resync and update the database. Updating the table |
|
|
|
# successfully resync and update the database. Updating the table |
|
|
@ -1260,18 +1224,6 @@ class DeviceListUpdater(DeviceListWorkerUpdater): |
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
async def user_device_resync( |
|
|
|
|
|
|
|
self, user_id: str, mark_failed_as_stale: bool = True |
|
|
|
|
|
|
|
) -> Optional[JsonDict]: |
|
|
|
|
|
|
|
result, failed = await self._user_device_resync_returning_failed(user_id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if failed and mark_failed_as_stale: |
|
|
|
|
|
|
|
# Mark the remote user's device list as stale so we know we need to retry |
|
|
|
|
|
|
|
# it later. |
|
|
|
|
|
|
|
await self.store.mark_remote_users_device_caches_as_stale((user_id,)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _user_device_resync_returning_failed( |
|
|
|
async def _user_device_resync_returning_failed( |
|
|
|
self, user_id: str |
|
|
|
self, user_id: str |
|
|
|
) -> Tuple[Optional[JsonDict], bool]: |
|
|
|
) -> Tuple[Optional[JsonDict], bool]: |
|
|
|