eager-load comment votes and their users when showing threads
This commit is contained in:
parent
7f5114d0f1
commit
04d6084d74
|
@ -286,7 +286,7 @@ class CommentsController < ApplicationController
|
|||
comments = Comment.where(
|
||||
:thread_id => thread_ids
|
||||
).includes(
|
||||
:user, :story
|
||||
:user, :story, :hat, :votes => :user
|
||||
).arrange_for_user(
|
||||
@showing_user
|
||||
)
|
||||
|
|
|
@ -134,8 +134,8 @@ class StoriesController < ApplicationController
|
|||
|
||||
@short_url = @story.short_id_url
|
||||
|
||||
@comments = @story.merged_comments.includes(:user, :story,
|
||||
:hat).arrange_for_user(@user)
|
||||
@comments = @story.merged_comments.includes(:user, :story, :hat,
|
||||
:votes => :user).arrange_for_user(@user)
|
||||
|
||||
@force_show_thread_id = nil
|
||||
|
||||
|
|
|
@ -449,7 +449,8 @@ class Comment < ActiveRecord::Base
|
|||
def vote_summary_for_user(u)
|
||||
r_counts = {}
|
||||
r_users = {}
|
||||
self.votes.includes(:user).each do |v|
|
||||
# don't includes(:user) here and assume the caller did this already
|
||||
self.votes.each do |v|
|
||||
r_counts[v.reason.to_s] ||= 0
|
||||
r_counts[v.reason.to_s] += v.vote
|
||||
|
||||
|
|
Loading…
Reference in a new issue