select only profile on most Person queries
This commit is contained in:
parent
13740da9b9
commit
e406426b81
3 changed files with 12 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue