comments: fix N+1 query when loading comment votes.

Doing both `@comments.includes(:votes)` and `comment.votes.active` forced votes to be loaded twice.
This commit is contained in:
evazion
2022-11-05 17:24:07 -05:00
parent 3f99b1093a
commit 59872d2ed5
3 changed files with 3 additions and 2 deletions

View File

@@ -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?