Skip to content
Extraits de code Groupes Projets
Valider 3935d978 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Take some queries out of views

parent 96005880
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -16,7 +16,7 @@ class ApplicationController < ActionController::Base ...@@ -16,7 +16,7 @@ class ApplicationController < ActionController::Base
if user_signed_in? if user_signed_in?
@aspect = nil @aspect = nil
@object_aspect_ids = [] @object_aspect_ids = []
@all_aspects = current_user.aspects @all_aspects = current_user.aspects.includes(:aspect_memberships)
@aspects_dropdown_array = @all_aspects.collect{|x| [x.to_s, x.id]} @aspects_dropdown_array = @all_aspects.collect{|x| [x.to_s, x.id]}
@notification_count = Notification.for(current_user, :unread =>true).count @notification_count = Notification.for(current_user, :unread =>true).count
end end
......
...@@ -11,9 +11,9 @@ class AspectsController < ApplicationController ...@@ -11,9 +11,9 @@ class AspectsController < ApplicationController
def index def index
if params[:a_ids] if params[:a_ids]
@aspects = current_user.aspects.where(:id => params[:a_ids]).includes(:contacts) @aspects = current_user.aspects.where(:id => params[:a_ids]).includes(:contacts => {:person => :profile})
else else
@aspects = current_user.aspects.includes(:contacts) @aspects = current_user.aspects.includes(:contacts => {:person => :profile})
end end
# redirect to signup # redirect to signup
...@@ -22,13 +22,12 @@ class AspectsController < ApplicationController ...@@ -22,13 +22,12 @@ class AspectsController < ApplicationController
else else
@aspect_ids = @aspects.map{|a| a.id} @aspect_ids = @aspects.map{|a| a.id}
post_ids = @aspects.map{|a| a.post_ids}.flatten!
@posts = StatusMessage.joins(:aspects).where(:pending => false, @posts = StatusMessage.joins(:aspects).where(:pending => false,
:aspects => {:id => @aspect_ids}).includes(:person, {:comments => :person}, :photos).select('DISTINCT `posts`.*').paginate( :aspects => {:id => @aspect_ids}).includes({:person => :profile}, {:comments => {:person => :profile}}, :photos).select('DISTINCT `posts`.*').paginate(
:page => params[:page], :per_page => 15, :order => 'created_at DESC') :page => params[:page], :per_page => 15, :order => 'created_at DESC')
@contacts = current_user.contacts.includes(:person).where(:pending => false) @contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
@aspect = :all unless params[:a_ids] @aspect = :all unless params[:a_ids]
...@@ -70,13 +69,13 @@ class AspectsController < ApplicationController ...@@ -70,13 +69,13 @@ class AspectsController < ApplicationController
end end
def show def show
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => :person).first @aspect = current_user.aspects.where(:id => params[:id]).first
redirect_to aspects_path('a_ids[]' => @aspect.id) redirect_to aspects_path('a_ids[]' => @aspect.id)
end end
def edit def edit
@aspect = current_user.aspects.where(:id => params[:id]).first @aspect = current_user.aspects.where(:id => params[:id]).first
@contacts = current_user.contacts.includes(:person).where(:pending => false) @contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
unless @aspect unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else else
...@@ -88,9 +87,9 @@ class AspectsController < ApplicationController ...@@ -88,9 +87,9 @@ class AspectsController < ApplicationController
def manage def manage
@aspect = :manage @aspect = :manage
@contacts = current_user.contacts.includes(:person).where(:pending => false) @contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
@remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender) @remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile)
@aspects = @all_aspects.includes(:contacts => :person) @aspects = @all_aspects.includes(:contacts => {:person => :profile})
end end
def update def update
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter