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

Commit

Permalink
Only handle receipts for own users
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jun 27, 2022
1 parent a7b010b commit 22bd551
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,22 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
sql = """
SELECT r.stream_id, r.room_id, r.user_id, e.stream_ordering
FROM receipts_linearized AS r, event_push_summary_last_receipt_stream_id AS eps, events AS e
WHERE r.stream_id > eps.stream_id AND r.event_id = e.event_id
WHERE r.stream_id > eps.stream_id AND r.event_id = e.event_id AND user_id LIKE ?
ORDER BY r.stream_id ASC
LIMIT ?
"""

txn.execute(sql, (limit,))
# We only want local users, so we add a dodgy filter to the above query
# and recheck it below.
user_filter = "%:" + self.hs.hostname

txn.execute(
sql,
(
user_filter,
limit,
),
)
rows = txn.fetchall()

if not rows:
Expand All @@ -860,6 +870,10 @@ def _handle_new_receipts_for_notifs_txn(self, txn: LoggingTransaction) -> bool:
# For each new read receipt we delete push actions from before it and
# recalculate the summary.
for _, room_id, user_id, stream_ordering in rows:
# Only handle our own read receipts.
if not self.hs.is_mine_id(user_id):
continue

txn.execute(
"""
DELETE FROM event_push_actions
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/test_event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_get_unread_push_actions_for_user_in_range_for_email(self) -> None:

def test_count_aggregation(self) -> None:
room_id = "!foo:example.com"
user_id = "@user1235:example.com"
user_id = "@user1235:test"

last_read_stream_ordering = [0]

Expand Down

0 comments on commit 22bd551

Please sign in to comment.