From 3fb822c6c55b936ba251a0774bfce756827f55a3 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 6 Apr 2011 12:29:05 -0700 Subject: [PATCH] Fix distinct problem --- lib/diaspora/user/querying.rb | 2 +- spec/models/user/querying_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 8cf573a09..b7d33a71e 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -20,7 +20,7 @@ module Diaspora opts[:hidden] ||= false order_with_table = 'posts.' + opts[:order] opts[:offset] = opts[:page].nil? || opts[:page] == 1 ? 0 : opts[:limit] * (opts[:page] - 1) - select_clause ='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_self = self.person.posts diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 49ccbc0cc..7cbca9b1c 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -37,14 +37,17 @@ describe User do end end it 'works' do #This is in one spec to save time + bob.raw_visible_posts.length.should == 15 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).length.should == 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).length.should == 15 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