mirror of
https://github.com/diaspora/diaspora.git
synced 2026-01-09 15:18:11 -05:00
Mark notifications as read in a single SQL query
There is no need to load all comments only to count them. Lets just let the database do all the work. If there are no comments found, nothing will happen anyway. Also already filter the comments to only search for notifications for own comments. And add some tests :)
This commit is contained in:
@@ -104,9 +104,8 @@ class PostService
|
||||
end
|
||||
|
||||
def mark_like_on_comment_notifications_read(post_id)
|
||||
comment_ids = Comment.where(commentable_id: post_id)
|
||||
|
||||
Notification.where(recipient_id: user.id, target_type: "Comment", target_id: comment_ids, unread: true)
|
||||
.update_all(unread: false) if comment_ids.any?
|
||||
Notification.where(recipient_id: user.id, target_type: "Comment",
|
||||
target_id: Comment.where(commentable_id: post_id, author_id: user.person.id),
|
||||
unread: true).update_all(unread: false) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user