@@ -1553,28 +1553,24 @@ async def add_device_change_to_streams(
15531553 if not device_ids :
15541554 return None
15551555
1556- num_stream_ids = len (device_ids )
1557- if hosts :
1558- # The `device_lists_outbound_pokes` wants a different stream ID for
1559- # each row, which is a row per host per device update.
1560- num_stream_ids = len (hosts ) * len (device_ids )
1561-
15621556 context = get_active_span_text_map ()
15631557
1564- def add_device_changes_txn (txn , stream_ids ):
1558+ def add_device_changes_txn (
1559+ txn , stream_ids_for_device_change , stream_ids_for_outbound_pokes
1560+ ):
15651561 self ._add_device_change_to_stream_txn (
15661562 txn ,
15671563 user_id ,
15681564 device_ids ,
1569- stream_ids ,
1565+ stream_ids_for_device_change ,
15701566 )
15711567
15721568 self ._add_device_outbound_room_poke_txn (
15731569 txn ,
15741570 user_id ,
15751571 device_ids ,
15761572 room_ids ,
1577- stream_ids ,
1573+ stream_ids_for_device_change ,
15781574 context ,
15791575 hosts_have_been_calculated = hosts is not None ,
15801576 )
@@ -1590,15 +1586,27 @@ def add_device_changes_txn(txn, stream_ids):
15901586 user_id ,
15911587 device_ids ,
15921588 hosts ,
1593- stream_ids ,
1589+ stream_ids_for_outbound_pokes ,
15941590 context ,
15951591 )
15961592
1593+ # The `device_lists_stream` wants a stream ID per device update.
1594+ num_stream_ids = len (device_ids )
1595+
1596+ if hosts :
1597+ # The `device_lists_outbound_pokes` wants a different stream ID for
1598+ # each row, which is a row per host per device update.
1599+ num_stream_ids += len (hosts ) * len (device_ids )
1600+
15971601 async with self ._device_list_id_gen .get_next_mult (num_stream_ids ) as stream_ids :
1602+ stream_ids_for_device_change = stream_ids [: len (device_ids )]
1603+ stream_ids_for_outbound_pokes = stream_ids [len (device_ids ) :]
1604+
15981605 await self .db_pool .runInteraction (
15991606 "add_device_change_to_stream" ,
16001607 add_device_changes_txn ,
1601- stream_ids ,
1608+ stream_ids_for_device_change ,
1609+ stream_ids_for_outbound_pokes ,
16021610 )
16031611
16041612 return stream_ids [- 1 ]
0 commit comments