From 194963a94e8027489368d698e864d10df02df3c9 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 30 Aug 2022 11:48:09 +0200 Subject: [PATCH] Fix sorting of results by newest/oldest (by updated_at) [SCI-7118] --- app/models/comment.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 7f145e946..5ae86fa4b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -52,7 +52,11 @@ class Comment < ApplicationRecord def self.mark_as_seen_by(user, commentable) # rubocop:disable Rails/SkipsModelValidations all.where('? = ANY (unseen_by)', user.id).update_all("unseen_by = array_remove(unseen_by, #{user.id.to_i}::bigint)") - commentable.touch + + # Because we want the number of unseen comments to affect the cache of project + # and experiment lists, we need to set the updated_at of Project or Experiment. + commentable.touch if commentable.class.in? [Project, Experiment] + # rubocop:enable Rails/SkipsModelValidations end end