Don't instantiate all contacts on aspects index, temporary querying in views for aspect listings

This commit is contained in:
Raphael Sofaer 2011-03-30 14:28:35 -07:00
parent 6364f2a332
commit 3b7063d44a
4 changed files with 24 additions and 12 deletions

View file

@ -16,7 +16,6 @@ class AspectsController < ApplicationController
else
@aspects = current_user.aspects
end
@aspects = @aspects.includes(:contacts => {:person => :profile})
# redirect to signup
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile? && !request.format.js?
@ -24,7 +23,16 @@ class AspectsController < ApplicationController
return
end
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
@selected_contacts_hashes = Contact.connection.execute(
current_user.contacts.joins(:person => :profile).select("people.id, people.guid, profiles.first_name, profiles.last_name, people.diaspora_handle, profiles.image_url_small, profiles.image_url_medium, profiles.image_url").to_sql
).map do |r|
{:id => r[1],
:name => Person.name_from_attrs(r[2], r[3], r[4]),
:avatar => Profile.image_url_from_attrs(:thumb_small, r[5], r[6], r[7]),
:handle => r[4],
:url => "/people/#{r[0]}"}
end
@aspect_ids = @aspects.map { |a| a.id }
@posts = current_user.raw_visible_posts(:by_members_of => @aspect_ids, :type => 'StatusMessage', :order => session[:sort_order] + ' DESC', :page => params[:page]).includes(
:comments, :mentions, :likes, :dislikes).paginate(:page => params[:page], :per_page => 15, :order => session[:sort_order] + ' DESC')

View file

@ -63,13 +63,17 @@ class Profile < ActiveRecord::Base
(self.person) ? self.person.diaspora_handle : self[:diaspora_handle]
end
def image_url(size = :thumb_large)
result = if size == :thumb_medium && self[:image_url_medium]
self[:image_url_medium]
elsif size == :thumb_small && self[:image_url_small]
self[:image_url_small]
def image_url(size_wanted = :thumb_large)
self.class.image_url_from_attrs(size_wanted, self[:image_url_small], self[:image_url_medium], self[:image_url])
end
def self.image_url_from_attrs(size_wanted, small, medium, large)
result = if size_wanted == :thumb_medium && medium
medium
elsif size_wanted == :thumb_small && small
small
else
self[:image_url]
large
end
result || '/images/user/default.png'
end

View file

@ -10,4 +10,4 @@
%ul
- for aspect in aspects
= render 'aspects/aspect', :aspect => aspect, :contacts => aspect.contacts.reject{|x| x.pending == true}
= render 'aspects/aspect', :aspect => aspect, :contacts => aspect.contacts.where(:pending => false).limit(16).includes(:person => :profile)

View file

@ -20,8 +20,8 @@
.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_contacts_hashes
= hidden_field_tag :contact_json, @selected_contacts_hashes.to_json
= status.error_messages
#file-upload
= image_tag 'icons/photos.png'