5
3
mirror of https://github.com/tildeverse/lobsters synced 2024-06-20 15:37:04 +00:00

eager-load comment votes and their users when showing threads

This commit is contained in:
joshua stein 2017-04-13 11:02:56 -05:00
parent 1185208081
commit 36fbb1ca30
3 changed files with 5 additions and 4 deletions

View File

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

View File

@ -135,8 +135,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

View File

@ -451,7 +451,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