diff --git a/app/models/comment.rb b/app/models/comment.rb index 55308962d..e15218c8a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -62,7 +62,7 @@ class Comment < ActiveRecord::Base def self.hash_from_post_ids post_ids hash = {} - comments = where(:post_id.in => post_ids) + comments = where(:post_id => post_ids) post_ids.each do |id| hash[id] = [] end diff --git a/app/models/person.rb b/app/models/person.rb index f49521e14..60d953393 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -168,6 +168,6 @@ class Person < ActiveRecord::Base private def remove_all_traces - Post.all(:person_id => id).each { |p| p.delete } + Post.where(:person_id => id).delete_all end end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 1ef9b4f7c..493ad33af 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -10,7 +10,7 @@ class StatusMessage < Post validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters" xml_name :status_message - xml_accessor :message + #xml_accessor :message has_many :photos, :dependent => :destroy validate :message_or_photos_present? diff --git a/app/models/user.rb b/app/models/user.rb index 085cd97fa..9dc344d7e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,8 +14,6 @@ class User < ActiveRecord::Base :recoverable, :rememberable, :trackable, :validatable, :timeoutable -# key :visible_post_ids, Array, :typecast => 'ObjectId' -# before_validation :strip_and_downcase_username, :on => :create before_validation :set_current_language, :on => :create @@ -38,9 +36,6 @@ class User < ActiveRecord::Base has_many :contacts has_many :contact_people, :through => :contacts has_many :services -# many :raw_visible_posts, :in => :visible_post_ids, :class => Post - -# many :services, :class => Service before_destroy :disconnect_everyone, :remove_person before_save do @@ -136,7 +131,7 @@ class User < ActiveRecord::Base def update_post(post, post_hash = {}) if self.owns? post post.update_attributes(post_hash) - aspects = aspects_with_post(post.id) + aspects = self.aspects.joins(:posts).where(:posts => {:id => post.id}) self.push_to_aspects(post, aspects) end end diff --git a/db/migrate/0000_create_schema.rb b/db/migrate/0000_create_schema.rb index a27cc6b43..bed1073ea 100644 --- a/db/migrate/0000_create_schema.rb +++ b/db/migrate/0000_create_schema.rb @@ -74,7 +74,7 @@ class CreateSchema < ActiveRecord::Migration t.integer :person_id t.boolean :public, :default => false t.string :diaspora_handle - t.boolean :pending + t.boolean :pending, :default => false t.integer :user_refs, :default => 0 t.string :type t.text :message diff --git a/db/schema.rb b/db/schema.rb index a5f61560b..36b992b61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -110,7 +110,7 @@ ActiveRecord::Schema.define(:version => 0) do t.integer "person_id" t.boolean "public", :default => false t.string "diaspora_handle" - t.boolean "pending" + t.boolean "pending", :default => false t.integer "user_refs", :default => 0 t.string "type" t.text "message" diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 0c66a3c86..be5da228b 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -11,7 +11,7 @@ module Diaspora end def raw_visible_posts - Post.joins(:post_visibilities => :aspect).where(:pending => false, :post_visibilities => {:aspects => {:user_id => self.id}}) + Post.joins(:aspects).where(:pending => false, :aspects => {:user_id => self.id}) end def visible_posts( opts = {} ) @@ -39,9 +39,9 @@ module Diaspora people = Person.where(:id => person_ids) if opts[:type] == 'remote' - people.delete_if{ |p| !p.owner.blank? } + people = people.where(:owner_id => nil) elsif opts[:type] == 'local' - people.delete_if{ |p| p.owner.blank? } + people = people.where('`people`.`owner_id` IS NOT NULL') end people end @@ -61,7 +61,7 @@ module Diaspora end def request_from(person) - Request.where(:sender_id => person.id, :recipient_id => self.person.id) + Request.where(:sender_id => person.id, :recipient_id => self.person.id).first end def posts_from(person) diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index 8db97d80f..1ad516bbe 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -94,9 +94,8 @@ module Diaspora else retraction.perform self.id aspects = self.aspects_with_person(retraction.person) - aspects.each{ |aspect| aspect.post_ids.delete(retraction.post_id.to_id) - aspect.save - } + PostVisibility.where(:post_id => retraction.post_id, + :aspect_id => aspects.map{|a| a.id}).delete_all end retraction end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 85b6437ea..ee37b53ee 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -37,7 +37,6 @@ describe User do connect_users(@user2, @aspect2, @user, @aspect) aspect3 = @user.aspects.create(:name => "Snoozers") @status_message1 = @user2.post :status_message, :message => "hi", :to => @aspect2.id - pp @status_message1 @status_message2 = @user2.post :status_message, :message => "hey", :public => true , :to => @aspect2.id @status_message3 = @user.post :status_message, :message => "hey", :public => true , :to => @aspect.id @status_message4 = @user2.post :status_message, :message => "blah", :public => true , :to => @aspect2.id @@ -76,34 +75,26 @@ describe User do it "selects by message contents" do query = @user2.visible_posts(:message => "hi") - pp @status_message1 - pp query.to_sql - pp query query.should == [@status_message1] end it "does not return pending posts" do @pending_status_message.pending.should be_true @user2.visible_posts.should_not include @pending_status_message - - @user2.visible_posts(:by_members_of => @aspect2).should_not include @pending_status_message end - context 'with two users' do - let!(:first_aspect) {@user.aspects.create(:name => 'bruisers')} - let!(:second_aspect) {@user.aspects.create(:name => 'losers')} - - it "queries by aspect" do - connect_users(@user, first_aspect, @user2, @user2.aspects.first) - @user.receive status_message1.to_diaspora_xml, @user2.person - - @user.visible_posts(:by_members_of => first_aspect).should =~ [status_message1] - @user.visible_posts(:by_members_of => second_aspect).should =~ [] - end - it '#find_visible_post_by_id' do - @user2.find_visible_post_by_id(status_message1.id).should == status_message1 - @user.find_visible_post_by_id(status_message1.id).should == nil - end + it "queries by aspect" do + query = @user.visible_posts(:by_members_of => @aspect) + query.include?(@status_message1).should == true + query.include?(@status_message2).should == true + query.include?(@status_message3).should == true + query.include?(@status_message4).should == true + query.include?(@status_message5).should == false + @user.visible_posts(:by_members_of => @user.aspects.create(:name => "aaaaah")).should be_empty + end + it '#find_visible_post_by_id' do + @user2.find_visible_post_by_id(@status_message1.id).should == @status_message1 + @user2.find_visible_post_by_id(@status_message5.id).should == nil end end end @@ -147,7 +138,8 @@ describe User do @user.people_in_aspects([first_aspect]).count.should == 4 @user.people_in_aspects([first_aspect], :type => 'remote').count.should == 1 - @user.people_in_aspects([first_aspect], :type => 'local').count.should == 3 + q = @user.people_in_aspects([first_aspect], :type => 'local') + q.count.should == 3 end it 'does not return people not connected to user on same pod' do diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 054e7a358..f950a331f 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -183,7 +183,7 @@ describe User do it 'should receive a salmon for a post' do user2.receive_salmon( salmon.xml_for user2.person ) - user2.visible_post_ids.include?(post.id).should be true + user2.raw_visible_posts.include?(post).should be_true end end end