Put a select limit on the person query on contactsController index, since we know exactly what we're doing with the data
This commit is contained in:
parent
7df883eaf0
commit
3c34749dd7
3 changed files with 24 additions and 5 deletions
|
|
@ -24,12 +24,11 @@ class ContactsController < ApplicationController
|
|||
format.html { @contacts = sort_and_paginate_profiles(@contacts) }
|
||||
format.mobile { @contacts = sort_and_paginate_profiles(@contacts) }
|
||||
format.json {
|
||||
@people = Person.joins(:contacts => :aspect_memberships).
|
||||
select('DISTINCT people.*').
|
||||
@people = Person.for_json.joins(:contacts => :aspect_memberships).
|
||||
where(:contacts => { :user_id => current_user.id },
|
||||
:aspect_memberships => { :aspect_id => params[:aspect_ids] })
|
||||
|
||||
render :json => @people.includes(:profile).to_json
|
||||
render :json => @people.to_json
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class Person < ActiveRecord::Base
|
|||
scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
|
||||
scope :remote, where('people.owner_id IS NULL')
|
||||
scope :local, where('people.owner_id IS NOT NULL')
|
||||
scope :for_json, select('DISTINCT people.id, people.diaspora_handle').includes(:profile)
|
||||
|
||||
def self.featured_users
|
||||
AppConfig[:featured_users].present? ? Person.where(:diaspora_handle => AppConfig[:featured_users]) : []
|
||||
|
|
@ -63,7 +64,7 @@ class Person < ActiveRecord::Base
|
|||
p
|
||||
end
|
||||
|
||||
|
||||
|
||||
def self.search_query_string(query)
|
||||
query = query.downcase
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,25 @@ describe Person do
|
|||
end
|
||||
|
||||
context 'scopes' do
|
||||
describe '.for_json' do
|
||||
it 'does not select public keys' do
|
||||
proc {
|
||||
Person.for_json.first.serialized_public_key
|
||||
}.should raise_error ActiveModel::MissingAttributeError
|
||||
end
|
||||
it 'eager loads profiles' do
|
||||
Person.for_json.first.loaded_profile?.should be_true
|
||||
end
|
||||
it 'selects distinct people' do
|
||||
aspect = bob.aspects.create(:name => 'hilarious people')
|
||||
aspect.contacts << bob.contact_for(eve.person)
|
||||
person_ids = Person.for_json.joins(:contacts => :aspect_memberships).
|
||||
where(:contacts => {:user_id => bob.id},
|
||||
:aspect_memberships => {:aspect_id => bob.aspect_ids}).map{|p| p.id}
|
||||
|
||||
person_ids.uniq.should == person_ids
|
||||
end
|
||||
end
|
||||
describe '.local' do
|
||||
it 'returns only local people' do
|
||||
Person.local =~ [@person]
|
||||
|
|
@ -28,7 +47,7 @@ describe Person do
|
|||
it 'searchs for a person if id is passed' do
|
||||
Person.find_from_id_or_username(:id => @person.id).id.should == @person.id
|
||||
end
|
||||
|
||||
|
||||
it 'searchs a person from a user if username is passed' do
|
||||
Person.find_from_id_or_username(:username => @user.username).id.should == @user.person.id
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue