From ef1b7644f3f08c11655cec045ffbc582be8f1f4c Mon Sep 17 00:00:00 2001
From: zhitomirskiyi <ilya@joindiaspora.com>
Date: Tue, 18 Jan 2011 16:38:31 -0800
Subject: [PATCH] got rid of more hash from

---
 app/controllers/people_controller.rb       | 37 ----------------
 app/models/comment.rb                      | 12 ------
 app/models/photo.rb                        | 15 -------
 spec/controllers/people_controller_spec.rb | 50 ----------------------
 spec/models/comment_spec.rb                | 35 ---------------
 5 files changed, 149 deletions(-)

diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb
index 70a27acf76..6d2c1c7d81 100644
--- a/app/controllers/people_controller.rb
+++ b/app/controllers/people_controller.rb
@@ -23,24 +23,6 @@ class PeopleController < ApplicationController
     end
   end
 
-  def hashes_for_people people, aspects
-    ids = people.map{|p| p.id}
-    requests = {}
-    Request.where(:sender_id => ids, :recipient_id => current_user.person.id).each do |r|
-      requests[r.id] = r
-    end
-    contacts = {}
-    Contact.where(:user_id => current_user.id, :person_id => ids).each do |contact|
-      contacts[contact.person_id] = contact
-    end
-    people.map{|p|
-      {:person => p,
-        :contact => contacts[p.id],
-        :request => requests[p.id],
-        :aspects => aspects}
-    }
-  end
-
   def show
     @person = Person.where(:id => params[:id]).first
     @post_type = :all
@@ -130,25 +112,6 @@ class PeopleController < ApplicationController
   end
 
   private
-  def hashes_for_posts posts
-    post_ids = posts.map{|p| p.id}
-    comment_hash = Comment.hash_from_post_ids post_ids
-    person_hash = Person.from_post_comment_hash comment_hash
-    photo_hash = Photo.hash_from_post_ids post_ids
-
-    posts.map do |post|
-      {:post => post,
-        :person => @person,
-        :photos => photo_hash[post.id],
-        :comments => comment_hash[post.id].map do |comment|
-          {:comment => comment,
-            :person => person_hash[comment.person_id],
-          }
-        end,
-      }
-    end
-  end
-
   def webfinger(account, opts = {})
     Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts)
   end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 73e9aabfd7..8b5816abf9 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -109,16 +109,4 @@ class Comment < ActiveRecord::Base
     verify_signature(creator_signature, person)
   end
 
-  def self.hash_from_post_ids post_ids
-    hash = {}
-    comments = where(:post_id => post_ids)
-    post_ids.each do |id|
-      hash[id] = []
-    end
-    comments.each do |comment|
-      hash[comment.post_id] << comment
-    end
-    hash.each_value {|comments| comments.sort!{|c1, c2| c1.created_at <=> c2.created_at }}
-    hash
-  end
 end
diff --git a/app/models/photo.rb b/app/models/photo.rb
index 706570903e..11afaae6c4 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -94,22 +94,7 @@ class Photo < Post
     }
   end
 
-  def self.hash_from_post_ids post_ids
-    hash = {}
-    photos = self.on_statuses(post_ids)
-    post_ids.each do |id|
-      hash[id] = []
-    end
-    photos.each do |photo|
-      hash[photo.status_message_id] << photo
-    end
-    hash.each_value {|photos| photos.sort!{|p1, p2| p1.created_at <=> p2.created_at }}
-    hash
-  end
   scope :on_statuses, lambda { |post_ids|
     where(:status_message_id => post_ids)
   }
-
 end
-
-
diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb
index 7d913f28c6..03c6d0139a 100644
--- a/spec/controllers/people_controller_spec.rb
+++ b/spec/controllers/people_controller_spec.rb
@@ -76,47 +76,6 @@ describe PeopleController do
       response.should be_success
     end
   end
-  describe '#hashes_from_people' do
-    before do
-      @everyone = []
-      10.times do
-        @everyone << Factory.create(:person)
-      end
-
-      user.send_contact_request_to(@everyone[3], aspect)
-      user.send_contact_request_to(@everyone[2], aspect)
-      user.activate_contact(@everyone[4], aspect)
-      user.activate_contact(@everyone[5], aspect)
-
-      user.reload
-      user.aspects.reload
-      @people = @everyone
-      @people.length.should == 10
-      @hashes = @controller.hashes_for_people(@people, user.aspects)
-    end
-    it 'has the correct result for no relationship' do
-      hash = @hashes.first
-
-      hash[:person].should == @people.first
-      hash[:contact].should be_false
-      hash[:request].should be_false
-      hash[:aspects].should == user.aspects
-    end
-    it 'has the correct result for a connected person' do
-      hash = @hashes[4]
-      hash[:person].should == @people[4]
-      hash[:contact].should be_true
-      hash[:contact].should_not be_pending
-      hash[:aspects].should == user.aspects
-    end
-    it 'has the correct result for a requested person' do
-      hash = @hashes[2]
-      hash[:person].should == @people[2]
-      hash[:contact].should be_true
-      hash[:contact].should be_pending
-      hash[:aspects].should == user.aspects
-    end
-  end
   describe '#index' do
     before do
       @eugene = Factory.create(:person,
@@ -127,15 +86,6 @@ describe PeopleController do
                      :last_name => "Korth"))
     end
 
-    it "assigns hashes" do
-      eugene2 = Factory.create(:person,
-        :profile => Factory(:profile, :first_name => "Eugene",
-                     :last_name => "w"))
-      get :index, :q => "Eu"
-      people = assigns[:hashes].map{|h| h[:person]}
-      people.should include @eugene
-      people.should include eugene2
-    end
     it "assigns people" do
       eugene2 = Factory.create(:person,
         :profile => Factory(:profile, :first_name => "Eugene",
diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb
index 7d7e480f49..a8405a1f1a 100644
--- a/spec/models/comment_spec.rb
+++ b/spec/models/comment_spec.rb
@@ -13,41 +13,6 @@ describe Comment do
 
   let!(:connecting) { connect_users(user, aspect, user2, aspect2) }
 
- describe '.hash_from_post_ids' do
-   before do
-      user.reload
-      @hello = user.post(:status_message, :message => "Hello.", :to => aspect.id)
-      @hi = user.post(:status_message, :message => "hi", :to => aspect.id)
-      @lonely = user.post(:status_message, :message => "Hello?", :to => aspect.id)
-
-      @c11 = user2.comment "why so formal?", :on => @hello
-      @c21 = user2.comment "lol hihihi", :on => @hi
-      @c12 = user.comment "I simply felt like issuing a greeting.  Do step off.", :on => @hello
-      @c22 = user.comment "stfu noob", :on => @hi
-
-      @c12.created_at = Time.now+10
-      @c12.save!
-      @c22.created_at = Time.now+10
-      @c22.save!
-    end
-    it 'returns an empty array for posts with no comments' do
-      Comment.hash_from_post_ids([@lonely.id]).should ==
-        {@lonely.id => []}
-    end
-    it 'returns a hash from posts to comments' do
-      Comment.hash_from_post_ids([@hello.id, @hi.id]).should ==
-        {@hello.id => [@c11, @c12],
-         @hi.id => [@c21, @c22]
-        }
-    end
-    it 'gets the people from the db' do
-      hash = Comment.hash_from_post_ids([@hello.id, @hi.id])
-      Person.from_post_comment_hash(hash).should == {
-        user.person.id => user.person,
-        user2.person.id => user2.person,
-      }
-    end
- end
 
  describe 'comment#notification_type' do
    let(:user3)   {Factory(:user)}
-- 
GitLab