Fix stream query
This commit is contained in:
parent
ee75426963
commit
06217a0a1d
2 changed files with 10 additions and 3 deletions
|
|
@ -29,8 +29,8 @@ module Diaspora
|
||||||
|
|
||||||
select_clause ='DISTINCT posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at'
|
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_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
|
posts_from_self = self.person.posts.where(:pending => false, :type => opts[:type])
|
||||||
|
|
||||||
if opts[:by_members_of]
|
if opts[:by_members_of]
|
||||||
posts_from_others = posts_from_others.joins(:contacts => :aspect_memberships).where(
|
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]}"
|
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_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
|
end
|
||||||
|
|
||||||
def visible_photos(opts = {})
|
def visible_photos(opts = {})
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,13 @@ describe User do
|
||||||
query = eve.visible_posts
|
query = eve.visible_posts
|
||||||
query.map{|p| p.id}.should =~ [@status_message1, @status_message2, @status_message3, @status_message4].map{|p| p.id}
|
query.map{|p| p.id}.should =~ [@status_message1, @status_message2, @status_message3, @status_message4].map{|p| p.id}
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue