Skip to content

Commit b71d277

Browse files
authored
Reduce work of calculating outbound device pokes (#17211)
1 parent a547b49 commit b71d277

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

changelog.d/17211.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce work of calculating outbound device lists updates.

synapse/handlers/device.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,13 @@ async def _handle_new_device_update_async(self) -> None:
906906
context=opentracing_context,
907907
)
908908

909+
await self.store.mark_redundant_device_lists_pokes(
910+
user_id=user_id,
911+
device_id=device_id,
912+
room_id=room_id,
913+
converted_upto_stream_id=stream_id,
914+
)
915+
909916
# Notify replication that we've updated the device list stream.
910917
self.notifier.notify_replication()
911918

synapse/storage/databases/main/devices.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,30 @@ def _add_device_outbound_poke_to_stream_txn(
21612161
},
21622162
)
21632163

2164+
async def mark_redundant_device_lists_pokes(
2165+
self,
2166+
user_id: str,
2167+
device_id: str,
2168+
room_id: str,
2169+
converted_upto_stream_id: int,
2170+
) -> None:
2171+
"""If we've calculated the outbound pokes for a given room/device list
2172+
update, mark any subsequent changes as already converted"""
2173+
2174+
sql = """
2175+
UPDATE device_lists_changes_in_room
2176+
SET converted_to_destinations = true
2177+
WHERE stream_id > ? AND user_id = ? AND device_id = ?
2178+
AND room_id = ? AND NOT converted_to_destinations
2179+
"""
2180+
2181+
def mark_redundant_device_lists_pokes_txn(txn: LoggingTransaction) -> None:
2182+
txn.execute(sql, (converted_upto_stream_id, user_id, device_id, room_id))
2183+
2184+
return await self.db_pool.runInteraction(
2185+
"mark_redundant_device_lists_pokes", mark_redundant_device_lists_pokes_txn
2186+
)
2187+
21642188
def _add_device_outbound_room_poke_txn(
21652189
self,
21662190
txn: LoggingTransaction,

0 commit comments

Comments
 (0)