Remove n-query problem from contact_list
This commit is contained in:
parent
e97081e8cd
commit
2c68bb0305
8 changed files with 31 additions and 14 deletions
|
|
@ -78,22 +78,24 @@ class AspectsController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@aspect = current_user.aspects.where(:id => params[:id]).first
|
||||
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
|
||||
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
|
||||
unless @aspect
|
||||
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
||||
else
|
||||
@aspect_ids = [@aspect.id]
|
||||
@aspect_contacts_count = @aspect.contacts.count
|
||||
@aspect_contacts_count = @aspect.contacts.length
|
||||
render :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
def manage
|
||||
Rails.logger.info("Controller time")
|
||||
@aspect = :manage
|
||||
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
|
||||
@remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile)
|
||||
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
|
||||
Rails.logger.info("VIEW TIME!!!!!!")
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ module AspectsHelper
|
|||
:class => 'added button'
|
||||
end
|
||||
|
||||
def aspect_membership_button(aspect_id, contact, person)
|
||||
if contact.nil? || !contact.aspect_ids.include?(aspect_id)
|
||||
add_to_aspect_button(aspect_id, person.id)
|
||||
def aspect_membership_button(aspect, contact, person)
|
||||
if contact.nil? || !aspect.contacts.include?(contact)
|
||||
add_to_aspect_button(aspect.id, person.id)
|
||||
else
|
||||
remove_from_aspect_button(aspect_id, person.id)
|
||||
remove_from_aspect_button(aspect.id, person.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
= button_to t('.remove_aspect'), @aspect, :method => "delete", :confirm => t('.confirm_remove_aspect'), :class => 'button'
|
||||
|
||||
- if @contacts.count > 0
|
||||
= render 'shared/contact_list', :aspect_id => @aspect.id, :contacts => @contacts
|
||||
= render 'shared/contact_list', :aspect => @aspect, :contacts => @contacts
|
||||
|
||||
#aspect_edit_controls
|
||||
= link_to t('.rename'), '#'
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
|
||||
- for aspect in @all_aspects
|
||||
%li{:data=>{:guid=>aspect.id}, :class => ("selected" if @object_aspect_ids.include?(aspect.id))}
|
||||
= link_for_aspect(aspect, :class => 'aspect_selector', :title => "#{aspect.contacts.count} contacts")
|
||||
= link_for_aspect(aspect, :class => 'aspect_selector', :title => "#{aspect.aspect_memberships.length} contacts")
|
||||
|
||||
%li
|
||||
= link_to '+', '#add_aspect_pane', :class => "add_aspect_button", :title => t('aspects.manage.add_a_new_aspect'), :rel => 'facebox'
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
%span.name
|
||||
= link_to aspect.name, aspect
|
||||
.right
|
||||
= aspect_membership_button(aspect.id, contact, person)
|
||||
= aspect_membership_button(aspect, contact, person)
|
||||
|
||||
- for aspect in aspects_without_person
|
||||
%li{:data=>{:guid=>aspect.id}}
|
||||
%span.name
|
||||
= link_to aspect.name, aspect
|
||||
.right
|
||||
= aspect_membership_button(aspect.id, contact, person)
|
||||
= aspect_membership_button(aspect, contact, person)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
%i= aspect.name
|
||||
.span-6.append-1.last
|
||||
%h3= t('.existing')
|
||||
= render 'shared/contact_list', :aspect_id => aspect.id, :contacts => contacts, :manage => defined?(manage)
|
||||
= render 'shared/contact_list', :aspect => aspect, :contacts => contacts, :manage => defined?(manage)
|
||||
|
||||
.span-7.last
|
||||
= render 'shared/add_contact', :aspect_id => aspect.id
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@
|
|||
.description
|
||||
= contact.person.diaspora_handle
|
||||
.right
|
||||
= aspect_membership_button(aspect_id, contact, contact.person)
|
||||
= aspect_membership_button(aspect, contact, contact.person)
|
||||
|
||||
|
|
|
|||
|
|
@ -88,14 +88,16 @@ describe AspectsController do
|
|||
connect_users(@user, @aspect0, user, aspect)
|
||||
post = @user.post(:status_message, :message => "hello#{n}", :to => @aspect1.id)
|
||||
@posts << post
|
||||
8.times do |n|
|
||||
user.comment "yo#{post.message}", :on => post
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'takes time' do
|
||||
Benchmark.realtime{
|
||||
get :index
|
||||
}.should < 1.5
|
||||
}.should < 0.8
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -141,6 +143,19 @@ describe AspectsController do
|
|||
get :manage
|
||||
response.should be_success
|
||||
end
|
||||
it "performs reasonably" do
|
||||
require 'benchmark'
|
||||
8.times do |n|
|
||||
aspect = @user.aspects.create(:name => "aspect#{n}")
|
||||
8.times do |o|
|
||||
person = Factory(:person)
|
||||
@user.activate_contact(person, aspect)
|
||||
end
|
||||
end
|
||||
Benchmark.realtime{
|
||||
get :manage
|
||||
}.should < 2
|
||||
end
|
||||
it "assigns aspect to manage" do
|
||||
get :manage
|
||||
assigns(:aspect).should == :manage
|
||||
|
|
|
|||
Loading…
Reference in a new issue