From 3296477531b7e95516ade0b3de1404c382c81023 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Fri, 4 Nov 2011 16:40:04 -0700 Subject: [PATCH] eager load author and profile for comments --- app/models/comment.rb | 2 ++ app/views/comments/_comments.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 71cfae25f..16edcf412 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -32,6 +32,8 @@ class Comment < ActiveRecord::Base serialize :youtube_titles, Hash + scope :including_author, includes(:author => :profile) + before_save do self.text.strip! unless self.text.nil? end diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml index f8cfa7e30..5f7d79c45 100644 --- a/app/views/comments/_comments.html.haml +++ b/app/views/comments/_comments.html.haml @@ -9,9 +9,9 @@ %ul.comments{:class => ('loaded' if post.comments.size <= 3)} -if post.comments.size > 3 && !comments_expanded && ! all_comments? - = render :partial => 'comments/comment', :collection => post.comments.last(3), :locals => {:post => post} + = render :partial => 'comments/comment', :collection => post.comments.last(3).including_author, :locals => {:post => post} -else - = render :partial => 'comments/comment', :collection => post.comments, :locals => {:post => post} + = render :partial => 'comments/comment', :collection => post.comments.including_author, :locals => {:post => post} - unless commenting_disabled?(post) .new_comment_form_wrapper{:class => comment_form_wrapper_class(post)}