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

Remove unused receipt methods. #12632

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12632.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unused code related to receipts.
54 changes: 0 additions & 54 deletions synapse/storage/databases/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Iterable,
List,
Optional,
Set,
Tuple,
cast,
)
Expand Down Expand Up @@ -117,33 +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]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This became unused in #8059, I think?

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
) -> 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]:
Expand Down Expand Up @@ -599,23 +571,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:
Expand All @@ -624,8 +579,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(
self,
Expand Down Expand Up @@ -842,13 +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._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),
Expand Down