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 b049733 commit 72d567d
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,34 +341,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,
+ receipts_args
+ [room_id, user_id, join_stream_ordering, join_stream_ordering],
)
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 72d567d

Please sign in to comment.