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)
This commit is contained in:
parent
3808547ac4
commit
72aee6b2c1
2 changed files with 4 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue