From e406426b81e1724c12c2da80c4091f44baaf7c9f Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 9 Dec 2010 14:56:34 -0800 Subject: [PATCH] select only profile on most Person queries --- app/controllers/aspects_controller.rb | 4 ++-- app/models/person.rb | 4 ++-- spec/controllers/aspects_controller_spec.rb | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 14230a636..afb6c7e54 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -145,7 +145,7 @@ class AspectsController < ApplicationController private def hashes_for_contacts contacts - people = Person.all(:id.in => contacts.map{|c| c.person_id}) + people = Person.all(:id.in => contacts.map{|c| c.person_id}, :fields => [:profile]) people_hash = {} people.each{|p| people_hash[p.id] = p} contacts.map{|c| {:contact => c, :person => people_hash[c.person_id.to_id]}} @@ -158,7 +158,7 @@ class AspectsController < ApplicationController c.aspect_ids.include?(a.id)} hash[:contact_count] = aspect_contacts.count person_ids = aspect_contacts.map{|c| c.person_id} - hash[:people] = Person.all({:id.in => person_ids}.merge(opts)) + hash[:people] = Person.all({:id.in => person_ids, :fields => [:profile]}.merge(opts)) hash end end diff --git a/app/models/person.rb b/app/models/person.rb index 8cbe00d7c..8ec8148f7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -154,8 +154,8 @@ class Person end def self.from_post_comment_hash(hash) - person_ids = hash.values.flatten.map{|c| c.person_id}.uniq - people = where(:id.in => person_ids) + person_ids = hash.values.flatten.map!{|c| c.person_id}.uniq + people = where(:id.in => person_ids).fields(:profile) people_hash = {} people.each{|p| people_hash[p.id] = p} people_hash diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 8ba7e98db..24bf67a41 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -172,6 +172,9 @@ describe AspectsController do it 'has a person' do @hash[:person].should == @user.contacts.first.person end + it "does not select the person's rsa key" do + @hash[:person].serialized_public_key.should be_nil + end end describe "#hashes_for_aspects" do before do @@ -191,13 +194,16 @@ describe AspectsController do @hash[:contact_count].should == @aspect.contacts.count end it 'has people' do - desired_people = @aspect.contacts.map{|c| c.person.diaspora_handle} - gotten_people = @hash[:people].map{|p| p.diaspora_handle} + desired_people = @aspect.contacts.map{|c| c.person.id} + gotten_people = @hash[:people].map{|p| p.id} gotten_people.each{|p| desired_people.should include p} end it 'takes a limit on people returned' do @hash[:people].length.should == 9 end + it "does not return the rsa key" do + @hash[:people].first.serialized_public_key.should be_nil + end end describe "#update" do