From e6836c46a7629fc7ffbb36a5e2c420ac1bbce7d7 Mon Sep 17 00:00:00 2001
From: Raphael Sofaer <raphael@joindiaspora.com>
Date: Wed, 9 Mar 2011 17:48:13 -0800
Subject: [PATCH] Remove unnecessary includes, finish renaming set_header_data,
 only run set_header_data on html requests

---
 app/controllers/application_controller.rb | 18 ++----------------
 app/controllers/contacts_controller.rb    |  5 +++--
 app/controllers/posts_controller.rb       |  2 +-
 app/controllers/publics_controller.rb     |  2 +-
 4 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index f8c99941f7..fbbfb067f6 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -23,10 +23,10 @@ class ApplicationController < ActionController::Base
   end
 
   def set_header_data
-    if user_signed_in?
+    if user_signed_in? && request.format.html?
       @aspect = nil
       @object_aspect_ids = []
-      @all_aspects = current_user.aspects.includes(:aspect_memberships)
+      @all_aspects = current_user.aspects
       @notification_count = Notification.for(current_user, :unread =>true).count
       @unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
     end
@@ -98,18 +98,4 @@ class ApplicationController < ActionController::Base
   def grammatical_gender
     @grammatical_gender || nil
   end
-
-  def similar_people contact, opts={}
-    opts[:limit] ||= 5
-    aspect_ids = contact.aspect_ids
-    count = Contact.count(:user_id => current_user.id,
-                          :person_id.ne => contact.person.id,
-                          :aspect_ids.in => aspect_ids)
-
-    if count > opts[:limit]
-      offset = rand(count-opts[:limit])
-    else
-      offset = 0
-    end
-  end
 end
diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb
index e165c3e656..a567fc8387 100644
--- a/app/controllers/contacts_controller.rb
+++ b/app/controllers/contacts_controller.rb
@@ -4,7 +4,7 @@
 
 class ContactsController < ApplicationController
   before_filter :authenticate_user!
-  
+
   def new
     @person = Person.find(params[:person_id])
     @aspects_with_person = []
@@ -40,6 +40,7 @@ class ContactsController < ApplicationController
   end
 
   def edit
+    @all_aspects ||= current_user.aspects
     @contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first
 
     @person = @contact.person
@@ -61,7 +62,7 @@ class ContactsController < ApplicationController
     else
       flash[:error] = I18n.t('contacts.destroy.failure', :name => contact.person.name)
     end
-    redirect_to contact.person 
+    redirect_to contact.person
   end
 
   private
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 9ab1395669..10c2c10cad 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -3,7 +3,7 @@
 #   the COPYRIGHT file.
 
 class PostsController < ApplicationController
-  skip_before_filter :set_contacts_notifications_unread_count_and_status
+  skip_before_filter :set_header_data
   skip_before_filter :count_requests
   skip_before_filter :set_invites
   skip_before_filter :set_locale
diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb
index 85806c76dc..5fd0105f49 100644
--- a/app/controllers/publics_controller.rb
+++ b/app/controllers/publics_controller.rb
@@ -6,7 +6,7 @@ class PublicsController < ApplicationController
   require File.join(Rails.root, '/lib/diaspora/parser')
   include Diaspora::Parser
 
-  skip_before_filter :set_contacts_notifications_unread_count_and_status, :except => [:create, :update]
+  skip_before_filter :set_header_data
   skip_before_filter :count_requests
   skip_before_filter :set_invites
   skip_before_filter :set_locale
-- 
GitLab