Skip to content
Extraits de code Groupes Projets
Valider 21bccedf rédigé par zhitomirskiyi's avatar zhitomirskiyi
Parcourir les fichiers

notification eagerly load the target

parent 5ac19491
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -18,7 +18,8 @@ class NotificationsController < ApplicationController ...@@ -18,7 +18,8 @@ class NotificationsController < ApplicationController
end end
def index def index
@notifications = Notification.for(current_user).include(:target).paginate :page => params[:page], :per_page => 25 @notifications = Notification.find(:all, :conditions => {:recipient_id => current_user.id},
:order => 'created_at desc', :include => [:target]).paginate :page => params[:page], :per_page => 25
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") } @group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") }
respond_with @notifications respond_with @notifications
end end
......
...@@ -11,7 +11,7 @@ class Notification < ActiveRecord::Base ...@@ -11,7 +11,7 @@ class Notification < ActiveRecord::Base
belongs_to :target, :polymorphic => true belongs_to :target, :polymorphic => true
def self.for(recipient, opts={}) def self.for(recipient, opts={})
self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc').include(:target) self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc')
end end
def self.notify(recipient, target, actor) def self.notify(recipient, target, actor)
......
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