Fix stream query

This commit is contained in:
Raphael Sofaer 2011-06-01 14:19:27 -07:00
parent ee75426963
commit 06217a0a1d
2 changed files with 10 additions and 3 deletions

View file

@ -29,8 +29,8 @@ module Diaspora
select_clause ='DISTINCT posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at'
posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
posts_from_self = self.person.posts
posts_from_others = Post.joins(:contacts).where( :pending => false, :type => opts[:type], :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
posts_from_self = self.person.posts.where(:pending => false, :type => opts[:type])
if opts[:by_members_of]
posts_from_others = posts_from_others.joins(:contacts => :aspect_memberships).where(
@ -44,7 +44,7 @@ module Diaspora
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)
Post.where(:id => post_ids).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
end
def visible_photos(opts = {})

View file

@ -126,6 +126,13 @@ describe User do
query = eve.visible_posts
query.map{|p| p.id}.should =~ [@status_message1, @status_message2, @status_message3, @status_message4].map{|p| p.id}
end
it 'is not emptied by a load of photos' do
15.times {
eve.build_post(:photo, :pending => false, :user_file=> File.open(photo_fixture_name), :to => eve.aspect_ids, :updated_at => Time.now + 1.day).save!
}
query = eve.visible_posts(:type => 'StatusMessage')
query.map{|p| p.id}.should =~ [@status_message1, @status_message2, @status_message3, @status_message4].map{|p| p.id}
end
end
end