From 21bccedf9ba0fd2061e3dde286a04926f6c4cc59 Mon Sep 17 00:00:00 2001
From: zhitomirskiyi <ilya@joindiaspora.com>
Date: Tue, 18 Jan 2011 17:22:48 -0800
Subject: [PATCH] notification eagerly load the target

---
 app/controllers/notifications_controller.rb | 3 ++-
 app/models/notification.rb                  | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb
index f07e8477f2..7856f6edfd 100644
--- a/app/controllers/notifications_controller.rb
+++ b/app/controllers/notifications_controller.rb
@@ -18,7 +18,8 @@ class NotificationsController < ApplicationController
   end
 
   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") }
     respond_with @notifications
   end
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 6f27a589d7..113ebbf2ff 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -11,7 +11,7 @@ class Notification < ActiveRecord::Base
   belongs_to :target, :polymorphic => true
 
   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
 
   def self.notify(recipient, target, actor)
-- 
GitLab