Don't instantiate all contacts on aspects index, temporary querying in views for aspect listings
This commit is contained in:
parent
6364f2a332
commit
3b7063d44a
4 changed files with 24 additions and 12 deletions
|
|
@ -16,7 +16,6 @@ class AspectsController < ApplicationController
|
||||||
else
|
else
|
||||||
@aspects = current_user.aspects
|
@aspects = current_user.aspects
|
||||||
end
|
end
|
||||||
@aspects = @aspects.includes(:contacts => {:person => :profile})
|
|
||||||
|
|
||||||
# redirect to signup
|
# redirect to signup
|
||||||
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile? && !request.format.js?
|
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile? && !request.format.js?
|
||||||
|
|
@ -24,7 +23,16 @@ class AspectsController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
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 }
|
@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(
|
@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')
|
:comments, :mentions, :likes, :dislikes).paginate(:page => params[:page], :per_page => 15, :order => session[:sort_order] + ' DESC')
|
||||||
|
|
@ -98,7 +106,7 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
|
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
|
||||||
|
|
||||||
@contacts_in_aspect = @aspect.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
|
@contacts_in_aspect = @aspect.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
|
||||||
c = Contact.arel_table
|
c = Contact.arel_table
|
||||||
if @contacts_in_aspect.empty?
|
if @contacts_in_aspect.empty?
|
||||||
|
|
|
||||||
|
|
@ -63,13 +63,17 @@ class Profile < ActiveRecord::Base
|
||||||
(self.person) ? self.person.diaspora_handle : self[:diaspora_handle]
|
(self.person) ? self.person.diaspora_handle : self[:diaspora_handle]
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_url(size = :thumb_large)
|
def image_url(size_wanted = :thumb_large)
|
||||||
result = if size == :thumb_medium && self[:image_url_medium]
|
self.class.image_url_from_attrs(size_wanted, self[:image_url_small], self[:image_url_medium], self[:image_url])
|
||||||
self[:image_url_medium]
|
end
|
||||||
elsif size == :thumb_small && self[:image_url_small]
|
|
||||||
self[:image_url_small]
|
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
|
else
|
||||||
self[:image_url]
|
large
|
||||||
end
|
end
|
||||||
result || '/images/user/default.png'
|
result || '/images/user/default.png'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,4 @@
|
||||||
|
|
||||||
%ul
|
%ul
|
||||||
- for aspect in aspects
|
- 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)
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
.content_creation
|
.content_creation
|
||||||
= form_for(StatusMessage.new, :remote => true, :html => {"data-type" => "json"}) do |status|
|
= form_for(StatusMessage.new, :remote => true, :html => {"data-type" => "json"}) do |status|
|
||||||
- if @selected_contacts
|
- if @selected_contacts_hashes
|
||||||
= hidden_field_tag :contact_json, @selected_contacts.map{|contact| contact.person}.to_json
|
= hidden_field_tag :contact_json, @selected_contacts_hashes.to_json
|
||||||
= status.error_messages
|
= status.error_messages
|
||||||
#file-upload
|
#file-upload
|
||||||
= image_tag 'icons/photos.png'
|
= image_tag 'icons/photos.png'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue