diff --git a/app/components/comment_component.rb b/app/components/comment_component.rb index 1ed50ffc9..88ed602b4 100644 --- a/app/components/comment_component.rb +++ b/app/components/comment_component.rb @@ -42,7 +42,7 @@ class CommentComponent < ApplicationComponent end def current_vote - @current_vote ||= comment.votes.active.find { |v| v.user_id == current_user.id } + @current_vote ||= comment.active_votes.find { |v| v.user_id == current_user.id } end def reported? diff --git a/app/components/comment_section_component.rb b/app/components/comment_section_component.rb index 0dec08161..6058f8e1a 100644 --- a/app/components/comment_section_component.rb +++ b/app/components/comment_section_component.rb @@ -11,7 +11,7 @@ class CommentSectionComponent < ApplicationComponent @comments = @post.comments.order(id: :asc) @comments = @comments.includes(:creator) - @comments = @comments.includes(:votes) if !current_user.is_anonymous? + @comments = @comments.includes(:active_votes) if !current_user.is_anonymous? @comments = @comments.includes(:pending_moderation_reports) if policy(ModerationReport).can_see_moderation_reports? @comments = @comments.last(limit) if limit.present? diff --git a/app/models/comment.rb b/app/models/comment.rb index c1f9da98c..4eeb6d16e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,6 +10,7 @@ class Comment < ApplicationRecord has_many :moderation_reports, as: :model, dependent: :destroy has_many :pending_moderation_reports, -> { pending }, as: :model, class_name: "ModerationReport" has_many :votes, class_name: "CommentVote", dependent: :destroy + has_many :active_votes, -> { active }, class_name: "CommentVote" has_many :mod_actions, as: :subject, dependent: :destroy validates :body, presence: true, length: { maximum: 15_000 }, if: :body_changed?