Stream query... FIXED?????
This commit is contained in:
parent
746a0c38b3
commit
fa41c1fc52
2 changed files with 27 additions and 26 deletions
|
|
@ -34,7 +34,7 @@ module Diaspora
|
|||
posts_from_others = posts_from_others.select(select_clause).limit(opts[:limit]).offset(opts[:offset]).order(order_with_table)
|
||||
posts_from_self = posts_from_self.select(select_clause).limit(opts[:limit]).offset(opts[:offset]).order(order_with_table)
|
||||
|
||||
all_posts = "(#{posts_from_others.to_sql}) UNION (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]}"
|
||||
all_posts = "(#{posts_from_others.to_sql}) UNION ALL (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]}"
|
||||
post_ids = Post.connection.execute(all_posts).map{|r| r.first}
|
||||
|
||||
Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,31 @@ describe User do
|
|||
stream.should include(visible_post)
|
||||
stream.should_not include(invisible_post)
|
||||
end
|
||||
context 'with many posts' do
|
||||
before do
|
||||
bob.move_contact(eve.person, bob.aspects.first, bob.aspects.create(:name => 'new aspect'))
|
||||
(1..25).each do |n|
|
||||
[alice, bob, eve].each do |u|
|
||||
post = u.post :status_message, :text => "#{u.username} - #{n}", :to => u.aspects.first.id
|
||||
post.created_at = post.created_at + n*1000*u.id
|
||||
post.updated_at = post.updated_at + n*1000*u.id
|
||||
post.save
|
||||
end
|
||||
end
|
||||
end
|
||||
it 'works' do #This is in one spec to save time
|
||||
bob.raw_visible_posts.should == bob.raw_visible_posts(:by_members_of => bob.aspects.map{|a| a.id})
|
||||
bob.raw_visible_posts.sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts.map{|p| p.id}.reverse
|
||||
|
||||
opts = {:limit => 40}
|
||||
bob.raw_visible_posts(opts).should == bob.raw_visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id}))
|
||||
bob.raw_visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts(opts).map{|p| p.id}.reverse
|
||||
|
||||
opts = {:page => 2}
|
||||
bob.raw_visible_posts(opts).map{|p| p.id}.should == bob.raw_visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id})).map{|p| p.id}
|
||||
bob.raw_visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts(opts).map{|p| p.id}.reverse
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with two posts' do
|
||||
|
|
@ -130,33 +155,9 @@ describe User do
|
|||
alice.people_in_aspects([eve.aspects.first]).should == []
|
||||
end
|
||||
end
|
||||
context 'with many posts' do
|
||||
before do
|
||||
bob.move_contact(eve.person, bob.aspects.first, bob.aspects.create(:name => 'new aspect'))
|
||||
(1..25).each do |n|
|
||||
[alice, bob, eve].each do |u|
|
||||
post = u.post :status_message, :text => "#{u.username} - #{n}", :to => u.aspects.first.id
|
||||
post.created_at = post.created_at + n*1000*u.id
|
||||
post.updated_at = post.updated_at + n*1000*u.id
|
||||
post.save
|
||||
end
|
||||
end
|
||||
end
|
||||
it 'works' do #This is in one spec to save time
|
||||
bob.raw_visible_posts.should == bob.raw_visible_posts(:by_members_of => bob.aspects.map{|a| a.id})
|
||||
bob.raw_visible_posts.sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts.map{|p| p.id}.reverse
|
||||
|
||||
opts = {:limit => 40}
|
||||
bob.raw_visible_posts(opts).should == bob.raw_visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id}))
|
||||
bob.raw_visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts(opts).map{|p| p.id}.reverse
|
||||
|
||||
opts = {:page => 2}
|
||||
bob.raw_visible_posts(opts).map{|p| p.id}.should == bob.raw_visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id})).map{|p| p.id}
|
||||
bob.raw_visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts(opts).map{|p| p.id}.reverse
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'contact querying' do
|
||||
let(:person_one) { Factory.create :person }
|
||||
let(:person_two) { Factory.create :person }
|
||||
|
|
|
|||
Loading…
Reference in a new issue