Skip to content
Snippets Groups Projects
Commit 72aee6b2 authored by danielgrippi's avatar danielgrippi
Browse files

don't use .last(3), use .limit(3) instead. also, don't put an order on an...

don't use .last(3), use .limit(3) instead.  also, don't put an order on an association as it isn't overridable.  (this commit minimizes AR object instantiation in the stream)
parent 3808547a
No related branches found
No related tags found
No related merge requests found
......@@ -67,7 +67,9 @@ class Post < ActiveRecord::Base
# gives the last three comments on the post
def last_three_comments
return if self.comments_count == 0
self.comments.includes(:author => :profile).last(3)
# DO NOT USE .last(3) HERE. IT WILL FETCH ALL COMMENTS AND RETURN THE LAST THREE
# INSTEAD OF DOING THE FOLLOWING, AS EXPECTED (THX AR):
self.comments.order('created_at DESC').limit(3).includes(:author => :profile).reverse!
end
def self.excluding_blocks(user)
......
......@@ -6,7 +6,7 @@ module Diaspora
module Commentable
def self.included(model)
model.instance_eval do
has_many :comments, :as => :commentable, :order => 'created_at', :dependent => :destroy
has_many :comments, :as => :commentable, :dependent => :destroy
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment