From a5664b85896ea7c4914028c1a302ab55f914abd1 Mon Sep 17 00:00:00 2001 From: Deimos Date: Thu, 9 Aug 2018 18:16:50 -0600 Subject: [PATCH] Sort previous notifications when marking all read Because of the way the topic_visits update works (only updating visits that were before the comment was posted), this will only behave correctly when the previous notifications are processed in the order their comments were posted. This process needs to be replaced soon anyway, but this should make it work correctly for now. --- tildes/tildes/views/api/web/comment.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tildes/tildes/views/api/web/comment.py b/tildes/tildes/views/api/web/comment.py index 647e52c..b7d6b54 100644 --- a/tildes/tildes/views/api/web/comment.py +++ b/tildes/tildes/views/api/web/comment.py @@ -348,6 +348,11 @@ def put_mark_comments_read( .all() ) + # sort the notifications by created_time of their comment so that the + # INSERT ... ON CONFLICT DO UPDATE statements work as expected + prev_notifications = sorted( + prev_notifications, key=lambda c: c.comment.created_time) + for comment_notification in prev_notifications: comment_notification.is_unread = False _increment_topic_comments_seen(