Skip to content
Extraits de code Groupes Projets
Valider 3af5e24a rédigé par MrZYX's avatar MrZYX
Parcourir les fichiers

reduce db quries on aspects#index

parent 52fee96b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -31,7 +31,7 @@ class AspectsController < ApplicationController
@aspect_ids = @aspects.map{|a| a.id}
@posts = StatusMessage.joins(:aspects).where(:pending => false,
:aspects => {:id => @aspect_ids}).includes(:comments, :photos, :likes, :dislikes).select('DISTINCT `posts`.*').paginate(
:aspects => {:id => @aspect_ids}).includes(:aspects, :post_visibilities, :comments, :photos, :likes, :dislikes).select('DISTINCT `posts`.*').paginate(
:page => params[:page], :per_page => 15, :order => sort_order + ' DESC')
@fakes = PostsFake.new(@posts)
......
......@@ -21,13 +21,13 @@ module ApplicationHelper
def aspects_with_post aspects, post
aspects.select do |aspect|
PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id)
aspect.has_post?(post)
end
end
def aspects_without_post aspects, post
aspects.reject do |aspect|
PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id)
aspect.has_post?(post)
end
end
......
......@@ -21,6 +21,14 @@ class Aspect < ActiveRecord::Base
name.strip!
end
def has_post? post
post_ids = post_visibilities.each { |pv| pv.post_id }
post_ids.each { |id|
return true if id == post.id
}
return false
end
def to_s
name
end
......
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