From f161377480c6109a356253052cfc4fc016ce0203 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Sat, 2 Jul 2011 16:28:52 -0700 Subject: [PATCH] Stop loading contact objects on the main page, all we need is people --- app/controllers/aspects_controller.rb | 8 ++++---- app/views/aspects/_selected_contacts.html.haml | 6 +++--- app/views/aspects/index.html.haml | 2 +- app/views/aspects/index.js.erb | 2 +- app/views/shared/_publisher.html.haml | 4 ++-- spec/factories.rb | 1 - 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 7d8076e59..d7cc8fcf0 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -27,10 +27,10 @@ class AspectsController < ApplicationController end unless params[:only_posts] - all_selected_contacts = Contact.joins(:aspect_memberships). - where(:aspect_memberships => {:aspect_id => aspect_ids}) - @selected_contacts_count = all_selected_contacts.count - @selected_contacts = all_selected_contacts.includes(:person => :profile) + all_selected_people = Person.joins(:contacts => :aspect_memberships). + where(:contacts => {:user_id => current_user.id}, + :aspect_memberships => {:aspect_id => aspect_ids}) + @selected_people = all_selected_people.select("DISTINCT people.*").includes(:profile) end @aspect_ids = @aspects.map { |a| a.id } diff --git a/app/views/aspects/_selected_contacts.html.haml b/app/views/aspects/_selected_contacts.html.haml index 01ef4d5c0..d882922b3 100644 --- a/app/views/aspects/_selected_contacts.html.haml +++ b/app/views/aspects/_selected_contacts.html.haml @@ -8,9 +8,9 @@ = "(#{count})" .content - - if contacts.size > 0 - - for contact in contacts - = person_image_link contact.person + - if people.size > 0 + - for person in people + = person_image_link person - if @aspect_ids.size > 1 = link_to t('.view_all_contacts'), contacts_path, :id => "view_all_contacts_link" diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 4573e5635..85ded3816 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -23,7 +23,7 @@ :posts => @posts .span-5.rightBar.last - = render 'selected_contacts', :contacts => @selected_contacts[0..19], :count => @selected_contacts_count + = render 'selected_contacts', :people => @selected_people[0..19], :count => @selected_people.size .section .title diff --git a/app/views/aspects/index.js.erb b/app/views/aspects/index.js.erb index 664d22f52..1d61bd5a1 100644 --- a/app/views/aspects/index.js.erb +++ b/app/views/aspects/index.js.erb @@ -1,3 +1,3 @@ $('#aspect_stream_container').html("<%= escape_javascript(render('aspects/aspect_stream', :aspect => @aspect, :aspect_ids => @aspect_ids, :posts => @posts)) %>"); -$('#selected_aspect_contacts').html("<%= escape_javascript(render('aspects/selected_contacts', :count => @selected_contacts_count, :contacts => @selected_contacts[0..19])) %>"); +$('#selected_aspect_contacts').html("<%= escape_javascript(render('aspects/selected_contacts', :people => @selected_people[0..19], :count => @selected_people.size )) %>"); $('#aspect_stream_container a[rel*=facebox]').facebox(); diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index 09a20c826..22003d141 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -12,8 +12,8 @@ #publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )} .content_creation = form_for(StatusMessage.new, :remote => true, :html => {"data-type" => "json"}) do |status| - - if @selected_contacts - = hidden_field_tag :contact_json, @selected_contacts.map{|contact| contact.person}.to_json + - if @selected_people + = hidden_field_tag :contact_json, @selected_people.to_json = status.error_messages %p %params diff --git a/spec/factories.rb b/spec/factories.rb index da550151b..f25b92fbe 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -5,7 +5,6 @@ #For Guidance #http://github.com/thoughtbot/factory_girl # http://railscasts.com/episodes/158-factories-not-fixtures -#This inclsion, because gpg-agent(not needed) is never run and hence never sets any env. variables on a MAC def r_str ActiveSupport::SecureRandom.hex(3)