From 01dd56b46cdf8f38fe46c4f0bc76f8f711ca5717 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 4 May 2022 12:42:03 -0400 Subject: [PATCH 1/3] Remove unused get_users_with_read_receipts_in_room method. --- synapse/storage/databases/main/receipts.py | 30 ---------------------- 1 file changed, 30 deletions(-) diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py index 9e3d838eab9a..c65850e86ffe 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py @@ -22,7 +22,6 @@ Iterable, List, Optional, - Set, Tuple, cast, ) @@ -117,11 +116,6 @@ def get_max_receipt_stream_id(self) -> int: """Get the current max stream ID for receipts stream""" return self._receipts_id_gen.get_current_token() - @cached() - async def get_users_with_read_receipts_in_room(self, room_id: str) -> Set[str]: - receipts = await self.get_receipts_for_room(room_id, ReceiptTypes.READ) - return {r["user_id"] for r in receipts} - @cached() async def get_receipts_for_room( self, room_id: str, receipt_type: str @@ -599,23 +593,6 @@ def get_all_updated_receipts_txn( "get_all_updated_receipts", get_all_updated_receipts_txn ) - def _invalidate_get_users_with_receipts_in_room( - self, room_id: str, receipt_type: str, user_id: str - ) -> None: - if receipt_type != ReceiptTypes.READ: - return - - res = self.get_users_with_read_receipts_in_room.cache.get_immediate( - room_id, None, update_metrics=False - ) - - if res and user_id in res: - # We'd only be adding to the set, so no point invalidating if the - # user is already there - return - - self.get_users_with_read_receipts_in_room.invalidate((room_id,)) - def invalidate_caches_for_receipt( self, room_id: str, receipt_type: str, user_id: str ) -> None: @@ -624,7 +601,6 @@ def invalidate_caches_for_receipt( self._get_last_receipt_event_id_for_user.invalidate( (user_id, room_id, receipt_type) ) - self._invalidate_get_users_with_receipts_in_room(room_id, receipt_type, user_id) self.get_receipts_for_room.invalidate((room_id, receipt_type)) def process_replication_rows( @@ -843,12 +819,6 @@ def insert_graph_receipt_txn( assert self._can_write_to_receipts txn.call_after(self.get_receipts_for_room.invalidate, (room_id, receipt_type)) - txn.call_after( - self._invalidate_get_users_with_receipts_in_room, - room_id, - receipt_type, - user_id, - ) txn.call_after( self._get_receipts_for_user_with_orderings.invalidate, (user_id, receipt_type), From 37296bb08d26529461c79e185847847e458a8286 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 4 May 2022 12:42:33 -0400 Subject: [PATCH 2/3] Remove unused get_receipts_for_room method. --- synapse/storage/databases/main/receipts.py | 24 ---------------------- 1 file changed, 24 deletions(-) diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py index c65850e86ffe..d035969a3178 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py @@ -116,28 +116,6 @@ def get_max_receipt_stream_id(self) -> int: """Get the current max stream ID for receipts stream""" return self._receipts_id_gen.get_current_token() - @cached() - async def get_receipts_for_room( - self, room_id: str, receipt_type: str - ) -> List[Dict[str, Any]]: - """ - Fetch the event IDs for the latest receipt for all users in a room with the given receipt type. - - Args: - room_id: The room ID to fetch the receipt for. - receipt_type: The receipt type to fetch. - - Returns: - A list of dictionaries, one for each user ID. Each dictionary - contains a user ID and the event ID of that user's latest receipt. - """ - return await self.db_pool.simple_select_list( - table="receipts_linearized", - keyvalues={"room_id": room_id, "receipt_type": receipt_type}, - retcols=("user_id", "event_id"), - desc="get_receipts_for_room", - ) - async def get_last_receipt_event_id_for_user( self, user_id: str, room_id: str, receipt_types: Iterable[str] ) -> Optional[str]: @@ -601,7 +579,6 @@ def invalidate_caches_for_receipt( self._get_last_receipt_event_id_for_user.invalidate( (user_id, room_id, receipt_type) ) - self.get_receipts_for_room.invalidate((room_id, receipt_type)) def process_replication_rows( self, @@ -818,7 +795,6 @@ def insert_graph_receipt_txn( ) -> None: assert self._can_write_to_receipts - txn.call_after(self.get_receipts_for_room.invalidate, (room_id, receipt_type)) txn.call_after( self._get_receipts_for_user_with_orderings.invalidate, (user_id, receipt_type), From ee4989e90db5fd0029821de86351f98c3fe143cc Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 4 May 2022 12:56:21 -0400 Subject: [PATCH 3/3] Newsfragment --- changelog.d/12632.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12632.misc diff --git a/changelog.d/12632.misc b/changelog.d/12632.misc new file mode 100644 index 000000000000..9e4ba79c794f --- /dev/null +++ b/changelog.d/12632.misc @@ -0,0 +1 @@ +Remove unused code related to receipts.