diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index ab932c34a..f953ab221 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -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 = {}) diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index e5dcf7079..c4aa200bd 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -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