mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 12:04:56 -04:00
Convert additional databases to async/await (#8199)
This commit is contained in:
parent
5bf8e5f55b
commit
54f8d73c00
7 changed files with 147 additions and 137 deletions
|
@ -313,9 +313,9 @@ class DeviceWorkerStore(SQLBaseStore):
|
|||
|
||||
return results
|
||||
|
||||
def _get_last_device_update_for_remote_user(
|
||||
async def _get_last_device_update_for_remote_user(
|
||||
self, destination: str, user_id: str, from_stream_id: int
|
||||
):
|
||||
) -> int:
|
||||
def f(txn):
|
||||
prev_sent_id_sql = """
|
||||
SELECT coalesce(max(stream_id), 0) as stream_id
|
||||
|
@ -326,12 +326,16 @@ class DeviceWorkerStore(SQLBaseStore):
|
|||
rows = txn.fetchall()
|
||||
return rows[0][0]
|
||||
|
||||
return self.db_pool.runInteraction("get_last_device_update_for_remote_user", f)
|
||||
return await self.db_pool.runInteraction(
|
||||
"get_last_device_update_for_remote_user", f
|
||||
)
|
||||
|
||||
def mark_as_sent_devices_by_remote(self, destination: str, stream_id: int):
|
||||
async def mark_as_sent_devices_by_remote(
|
||||
self, destination: str, stream_id: int
|
||||
) -> None:
|
||||
"""Mark that updates have successfully been sent to the destination.
|
||||
"""
|
||||
return self.db_pool.runInteraction(
|
||||
await self.db_pool.runInteraction(
|
||||
"mark_as_sent_devices_by_remote",
|
||||
self._mark_as_sent_devices_by_remote_txn,
|
||||
destination,
|
||||
|
@ -684,7 +688,7 @@ class DeviceWorkerStore(SQLBaseStore):
|
|||
desc="make_remote_user_device_cache_as_stale",
|
||||
)
|
||||
|
||||
def mark_remote_user_device_list_as_unsubscribed(self, user_id: str):
|
||||
async def mark_remote_user_device_list_as_unsubscribed(self, user_id: str) -> None:
|
||||
"""Mark that we no longer track device lists for remote user.
|
||||
"""
|
||||
|
||||
|
@ -698,7 +702,7 @@ class DeviceWorkerStore(SQLBaseStore):
|
|||
txn, self.get_device_list_last_stream_id_for_remote, (user_id,)
|
||||
)
|
||||
|
||||
return self.db_pool.runInteraction(
|
||||
await self.db_pool.runInteraction(
|
||||
"mark_remote_user_device_list_as_unsubscribed",
|
||||
_mark_remote_user_device_list_as_unsubscribed_txn,
|
||||
)
|
||||
|
@ -959,9 +963,9 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
desc="update_device",
|
||||
)
|
||||
|
||||
def update_remote_device_list_cache_entry(
|
||||
async def update_remote_device_list_cache_entry(
|
||||
self, user_id: str, device_id: str, content: JsonDict, stream_id: int
|
||||
):
|
||||
) -> None:
|
||||
"""Updates a single device in the cache of a remote user's devicelist.
|
||||
|
||||
Note: assumes that we are the only thread that can be updating this user's
|
||||
|
@ -972,11 +976,8 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
device_id: ID of decivice being updated
|
||||
content: new data on this device
|
||||
stream_id: the version of the device list
|
||||
|
||||
Returns:
|
||||
Deferred[None]
|
||||
"""
|
||||
return self.db_pool.runInteraction(
|
||||
await self.db_pool.runInteraction(
|
||||
"update_remote_device_list_cache_entry",
|
||||
self._update_remote_device_list_cache_entry_txn,
|
||||
user_id,
|
||||
|
@ -1028,9 +1029,9 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
lock=False,
|
||||
)
|
||||
|
||||
def update_remote_device_list_cache(
|
||||
async def update_remote_device_list_cache(
|
||||
self, user_id: str, devices: List[dict], stream_id: int
|
||||
):
|
||||
) -> None:
|
||||
"""Replace the entire cache of the remote user's devices.
|
||||
|
||||
Note: assumes that we are the only thread that can be updating this user's
|
||||
|
@ -1040,11 +1041,8 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
user_id: User to update device list for
|
||||
devices: list of device objects supplied over federation
|
||||
stream_id: the version of the device list
|
||||
|
||||
Returns:
|
||||
Deferred[None]
|
||||
"""
|
||||
return self.db_pool.runInteraction(
|
||||
await self.db_pool.runInteraction(
|
||||
"update_remote_device_list_cache",
|
||||
self._update_remote_device_list_cache_txn,
|
||||
user_id,
|
||||
|
@ -1054,7 +1052,7 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
|
||||
def _update_remote_device_list_cache_txn(
|
||||
self, txn: LoggingTransaction, user_id: str, devices: List[dict], stream_id: int
|
||||
):
|
||||
) -> None:
|
||||
self.db_pool.simple_delete_txn(
|
||||
txn, table="device_lists_remote_cache", keyvalues={"user_id": user_id}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue