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
|
private
|
||||||
def hashes_for_contacts contacts
|
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_hash = {}
|
||||||
people.each{|p| people_hash[p.id] = p}
|
people.each{|p| people_hash[p.id] = p}
|
||||||
contacts.map{|c| {:contact => c, :person => people_hash[c.person_id.to_id]}}
|
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)}
|
c.aspect_ids.include?(a.id)}
|
||||||
hash[:contact_count] = aspect_contacts.count
|
hash[:contact_count] = aspect_contacts.count
|
||||||
person_ids = aspect_contacts.map{|c| c.person_id}
|
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
|
hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -154,8 +154,8 @@ class Person
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_post_comment_hash(hash)
|
def self.from_post_comment_hash(hash)
|
||||||
person_ids = hash.values.flatten.map{|c| c.person_id}.uniq
|
person_ids = hash.values.flatten.map!{|c| c.person_id}.uniq
|
||||||
people = where(:id.in => person_ids)
|
people = where(:id.in => person_ids).fields(:profile)
|
||||||
people_hash = {}
|
people_hash = {}
|
||||||
people.each{|p| people_hash[p.id] = p}
|
people.each{|p| people_hash[p.id] = p}
|
||||||
people_hash
|
people_hash
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,9 @@ describe AspectsController do
|
||||||
it 'has a person' do
|
it 'has a person' do
|
||||||
@hash[:person].should == @user.contacts.first.person
|
@hash[:person].should == @user.contacts.first.person
|
||||||
end
|
end
|
||||||
|
it "does not select the person's rsa key" do
|
||||||
|
@hash[:person].serialized_public_key.should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
describe "#hashes_for_aspects" do
|
describe "#hashes_for_aspects" do
|
||||||
before do
|
before do
|
||||||
|
|
@ -191,13 +194,16 @@ describe AspectsController do
|
||||||
@hash[:contact_count].should == @aspect.contacts.count
|
@hash[:contact_count].should == @aspect.contacts.count
|
||||||
end
|
end
|
||||||
it 'has people' do
|
it 'has people' do
|
||||||
desired_people = @aspect.contacts.map{|c| c.person.diaspora_handle}
|
desired_people = @aspect.contacts.map{|c| c.person.id}
|
||||||
gotten_people = @hash[:people].map{|p| p.diaspora_handle}
|
gotten_people = @hash[:people].map{|p| p.id}
|
||||||
gotten_people.each{|p| desired_people.should include p}
|
gotten_people.each{|p| desired_people.should include p}
|
||||||
end
|
end
|
||||||
it 'takes a limit on people returned' do
|
it 'takes a limit on people returned' do
|
||||||
@hash[:people].length.should == 9
|
@hash[:people].length.should == 9
|
||||||
end
|
end
|
||||||
|
it "does not return the rsa key" do
|
||||||
|
@hash[:people].first.serialized_public_key.should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#update" do
|
describe "#update" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue