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

Commit

Permalink
Fix postgres support.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Aug 16, 2022
1 parent 7900a3b commit 185b038
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,34 +353,35 @@ def _get_unread_counts_by_pos_txn(

txn.execute(
f"""
SELECT notif_count, COALESCE(unread_count, 0), thread_id, MAX(events.stream_ordering)
SELECT notif_count, COALESCE(unread_count, 0), thread_id
FROM event_push_summary
LEFT JOIN receipts_linearized USING (room_id, user_id, thread_id)
LEFT JOIN events ON (
events.room_id = receipts_linearized.room_id AND
events.event_id = receipts_linearized.event_id
)
WHERE event_push_summary.room_id = ? AND user_id = ?
LEFT JOIN (
SELECT thread_id, MAX(stream_ordering) AS stream_ordering
FROM receipts_linearized
LEFT JOIN events USING (room_id, event_id)
WHERE
user_id = ?
AND room_id = ?
AND {receipt_types_clause}
GROUP BY thread_id
) AS receipts USING (thread_id)
WHERE room_id = ? AND user_id = ?
AND (
-- Legacy, synchronously updated summary.
(
last_receipt_stream_ordering IS NULL
AND event_push_summary.stream_ordering > COALESCE(events.stream_ordering, ?)
AND event_push_summary.stream_ordering > COALESCE(receipts.stream_ordering, ?)
)
-- Up-to-date summary.
OR last_receipt_stream_ordering = COALESCE(events.stream_ordering, ?)
OR last_receipt_stream_ordering = COALESCE(receipts.stream_ordering, ?)
)
AND {receipt_types_clause}
""",
[room_id, user_id, join_stream_ordering, join_stream_ordering]
+ receipts_args,
[user_id, room_id]
+ receipts_args
+ [room_id, user_id, join_stream_ordering, join_stream_ordering], # type: ignore[list-item]
)
summarised_threads = set()
for notif_count, unread_count, thread_id, _ in txn:
# XXX Why are these returned? Related to MAX(...) aggregation.
if notif_count is None:
continue

for notif_count, unread_count, thread_id in txn:
summarised_threads.add(thread_id)

if not thread_id:
Expand Down

0 comments on commit 185b038

Please sign in to comment.