diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index 3c0fc756d4..a91b1ee4d5 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -505,8 +505,9 @@ class DeviceHandler(DeviceWorkerHandler):
"device_list_key", position, users={user_id}, rooms=room_ids
)
- # We may need to do some processing asynchronously.
- self._handle_new_device_update_async()
+ # We may need to do some processing asynchronously for local user IDs.
+ if self.hs.is_mine_id(user_id):
+ self._handle_new_device_update_async()
async def notify_user_signature_update(
self, from_user_id: str, user_ids: List[str]
@@ -683,9 +684,12 @@ class DeviceHandler(DeviceWorkerHandler):
self.federation_sender.send_device_messages(
host, immediate=False
)
- log_kv(
- {"message": "sent device update to host", "host": host}
- )
+ # TODO: when called, this isn't in a logging context.
+ # This leads to log spam, sentry event spam, and massive
+ # memory usage. See #12552.
+ # log_kv(
+ # {"message": "sent device update to host", "host": host}
+ # )
if current_stream_id != stream_id:
# Clear the set of hosts we've already sent to as we're
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py
index 318e4df376..483dd80406 100644
--- a/synapse/storage/databases/main/devices.py
+++ b/synapse/storage/databases/main/devices.py
@@ -1748,7 +1748,8 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
device_id,
room_id,
stream_id,
- False,
+ # We only need to calculate outbound pokes for local users
+ not self.hs.is_mine_id(user_id),
encoded_context,
)
for room_id in room_ids
@@ -1776,7 +1777,17 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
def get_uncoverted_outbound_room_pokes_txn(txn):
txn.execute(sql, (limit,))
- return txn.fetchall()
+
+ return [
+ (
+ user_id,
+ device_id,
+ room_id,
+ stream_id,
+ db_to_json(opentracing_context),
+ )
+ for user_id, device_id, room_id, stream_id, opentracing_context in txn
+ ]
return await self.db_pool.runInteraction(
"get_uncoverted_outbound_room_pokes", get_uncoverted_outbound_room_pokes_txn
|