Speed up person show
This commit is contained in:
parent
0f978b983a
commit
5eb0bf6736
2 changed files with 26 additions and 1 deletions
|
|
@ -78,7 +78,7 @@ module Diaspora
|
||||||
def posts_from(person)
|
def posts_from(person)
|
||||||
asp = Aspect.arel_table
|
asp = Aspect.arel_table
|
||||||
p = Post.arel_table
|
p = Post.arel_table
|
||||||
person.posts.includes(:aspects).where( p[:public].eq(true).or(asp[:user_id].eq(self.id))).select('DISTINCT `posts`.*').order("posts.updated_at DESC")
|
person.posts.includes(:aspects, :comments => {:person => :profile}).where( p[:public].eq(true).or(asp[:user_id].eq(self.id))).select('DISTINCT `posts`.*').order("posts.updated_at DESC")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,32 @@ describe PeopleController do
|
||||||
get :show, :id => @user.person.id
|
get :show, :id => @user.person.id
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
describe 'performance' do
|
||||||
|
before do
|
||||||
|
require 'benchmark'
|
||||||
|
@posts = []
|
||||||
|
@users = []
|
||||||
|
8.times do |n|
|
||||||
|
user = Factory.create(:user)
|
||||||
|
@users << user
|
||||||
|
aspect = user.aspects.create(:name => 'people')
|
||||||
|
connect_users(@user, @user.aspects.first, user, aspect)
|
||||||
|
|
||||||
|
@posts << @user.post(:status_message, :message => "hello#{n}", :to => aspect.id)
|
||||||
|
end
|
||||||
|
@posts.each do |post|
|
||||||
|
@users.each do |user|
|
||||||
|
user.comment "yo#{post.message}", :on => post
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'takes time' do
|
||||||
|
Benchmark.realtime{
|
||||||
|
get :show, :id => @user.person.id
|
||||||
|
}.should < 0.2
|
||||||
|
end
|
||||||
|
end
|
||||||
it 'renders with a post' do
|
it 'renders with a post' do
|
||||||
@user.post :status_message, :message => 'test more', :to => @aspect.id
|
@user.post :status_message, :message => 'test more', :to => @aspect.id
|
||||||
get :show, :id => @user.person.id
|
get :show, :id => @user.person.id
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue