diff --git a/app/controllers/notifications/trays_controller.rb b/app/controllers/notifications/trays_controller.rb index 26a1f06e5..c2bac662a 100644 --- a/app/controllers/notifications/trays_controller.rb +++ b/app/controllers/notifications/trays_controller.rb @@ -1,6 +1,6 @@ class Notifications::TraysController < ApplicationController def show - @notifications = Current.user.notifications.unread.ordered.limit(100) + @notifications = Current.user.notifications.preloaded.unread.ordered.limit(100) # Invalidate on the whole set instead of the unread set since the max updated at in the unread set # can stay the same when reading old notifications. diff --git a/app/models/card/assignable.rb b/app/models/card/assignable.rb index c43c50526..be0dd257e 100644 --- a/app/models/card/assignable.rb +++ b/app/models/card/assignable.rb @@ -15,7 +15,7 @@ module Card::Assignable end def assigned_to?(user) - assignments.exists? assignee: user + assignments.any? { |a| a.assignee_id == user.id } end def assigned? diff --git a/app/models/comment.rb b/app/models/comment.rb index a42b205fc..f81c465ad 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -4,11 +4,12 @@ class Comment < ApplicationRecord belongs_to :account, default: -> { card.account } belongs_to :card, touch: true belongs_to :creator, class_name: "User", default: -> { Current.user } - has_many :reactions, dependent: :delete_all + has_many :reactions, -> { order(:created_at) }, dependent: :delete_all has_rich_text :body scope :chronologically, -> { order created_at: :asc, id: :desc } + scope :preloaded, -> { with_rich_text_body.includes(reactions: :reacter) } scope :by_system, -> { joins(:creator).where(creator: { role: "system" }) } scope :by_user, -> { joins(:creator).where.not(creator: { role: "system" }) } diff --git a/app/models/notification.rb b/app/models/notification.rb index 416506783..545f6ab75 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -14,7 +14,7 @@ class Notification < ApplicationRecord after_destroy_commit :broadcast_read after_create :bundle - scope :preloaded, -> { preload(:creator, :account, source: [ :board, :creator ]) } + scope :preloaded, -> { preload(:creator, :account, source: [ :board, :creator, { eventable: [ :closure, :board, :assignments ] } ]) } delegate :notifiable_target, to: :source delegate :card, to: :source diff --git a/app/views/cards/_messages.html.erb b/app/views/cards/_messages.html.erb index c92c94f7c..402a39ec0 100644 --- a/app/views/cards/_messages.html.erb +++ b/app/views/cards/_messages.html.erb @@ -1,6 +1,6 @@ <%= messages_tag(card) do %> <% if card.published? %> - <%= render partial: "cards/comments/comment", collection: card.comments.chronologically, cached: true %> + <%= render partial: "cards/comments/comment", collection: card.comments.preloaded.chronologically, cached: true %> <%= render "cards/comments/new", card: card %> <%= render "cards/comments/watchers", card: card %> diff --git a/app/views/cards/comments/reactions/_reactions.html.erb b/app/views/cards/comments/reactions/_reactions.html.erb index 6de217842..ba3d491eb 100644 --- a/app/views/cards/comments/reactions/_reactions.html.erb +++ b/app/views/cards/comments/reactions/_reactions.html.erb @@ -1,7 +1,7 @@ <%= turbo_frame_tag comment, :reacting do %>