diff --git a/Gemfile b/Gemfile index c4a3cd80b..623aca3a1 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'mysql2', '0.2.6' #gem 'sqlite3' gem 'rails', '3.0.3' gem 'foreigner', '0.9.1' +gem 'activerecord-import' gem 'bundler', '>= 1.0.0' gem 'chef', '0.9.12', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 02b6de733..5c58dbded 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,8 @@ GEM activesupport (= 3.0.3) arel (~> 2.0.2) tzinfo (~> 0.3.23) + activerecord-import (0.2.7) + activerecord (~> 3.0.0) activeresource (3.0.3) activemodel (= 3.0.3) activesupport (= 3.0.3) @@ -447,6 +449,7 @@ PLATFORMS DEPENDENCIES SystemTimer (= 1.2.1) + activerecord-import acts-as-taggable-on! addressable (= 2.2.4) aws (= 2.3.32) diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 18a37ad01..36a74b4ff 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -42,9 +42,10 @@ class Services::Facebook < Service url = "https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=#{URI.escape(self.access_token)}" response = Faraday.get(url) data = JSON.parse(response.body)['data'] - data.each{ |p| - su = ServiceUser.find_or_initialize_by_service_id_and_uid(:service_id => self.id, :uid => p["id"]) - su.update_attributes({:name => p["name"], :photo_url => p["picture"]}) + ServiceUser.where(:service_id => self.id).delete_all + s_users = data.map{ |p| + ServiceUser.new(:service_id => self.id, :uid => p["id"], :photo_url => p["picture"], :name => p["name"]) } + ServiceUser.import(s_users) end end