Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 4ebb038

Browse files
committed
Return a dict from _get_receipts_by_room_txn.
1 parent e3512a7 commit 4ebb038

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

synapse/storage/databases/main/event_push_actions.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,18 @@ def f(txn: LoggingTransaction) -> List[str]:
559559

560560
def _get_receipts_by_room_txn(
561561
self, txn: LoggingTransaction, user_id: str
562-
) -> List[Tuple[str, int]]:
562+
) -> Dict[str, int]:
563+
"""
564+
Generate a map of room ID to the latest stream ordering that has been
565+
read by the given user.
566+
567+
Args:
568+
txn:
569+
user_id: The user to fetch receipts for.
570+
571+
Returns:
572+
A map of room ID to stream ordering for all rooms the user has a receipt in.
573+
"""
563574
receipt_types_clause, args = make_in_list_sql_clause(
564575
self.database_engine,
565576
"receipt_type",
@@ -580,7 +591,7 @@ def _get_receipts_by_room_txn(
580591

581592
args.extend((user_id,))
582593
txn.execute(sql, args)
583-
return cast(List[Tuple[str, int]], txn.fetchall())
594+
return dict(cast(List[Tuple[str, int]], txn.fetchall()))
584595

585596
async def get_unread_push_actions_for_user_in_range_for_http(
586597
self,
@@ -605,12 +616,10 @@ async def get_unread_push_actions_for_user_in_range_for_http(
605616
The list will have between 0~limit entries.
606617
"""
607618

608-
receipts_by_room = dict(
609-
await self.db_pool.runInteraction(
610-
"get_unread_push_actions_for_user_in_range_http_receipts",
611-
self._get_receipts_by_room_txn,
612-
user_id=user_id,
613-
),
619+
receipts_by_room = await self.db_pool.runInteraction(
620+
"get_unread_push_actions_for_user_in_range_http_receipts",
621+
self._get_receipts_by_room_txn,
622+
user_id=user_id,
614623
)
615624

616625
def get_push_actions_txn(
@@ -679,12 +688,10 @@ async def get_unread_push_actions_for_user_in_range_for_email(
679688
The list will have between 0~limit entries.
680689
"""
681690

682-
receipts_by_room = dict(
683-
await self.db_pool.runInteraction(
684-
"get_unread_push_actions_for_user_in_range_email_receipts",
685-
self._get_receipts_by_room_txn,
686-
user_id=user_id,
687-
),
691+
receipts_by_room = await self.db_pool.runInteraction(
692+
"get_unread_push_actions_for_user_in_range_email_receipts",
693+
self._get_receipts_by_room_txn,
694+
user_id=user_id,
688695
)
689696

690697
def get_push_actions_txn(

0 commit comments

Comments
 (0)