diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 30cbe1149..0857378d1 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -42,7 +42,7 @@ class PeopleController < ApplicationController #only do it if it is an email address if diaspora_id?(params[:q]) people = Person.where(:diaspora_handle => params[:q].downcase) - webfinger(params[:q]) if people.empty? + Webfinger.in_background(params[:q]) if people.empty? else people = Person.search(params[:q], current_user) end @@ -53,7 +53,7 @@ class PeopleController < ApplicationController #only do it if it is an email address if diaspora_id?(params[:q]) people = Person.where(:diaspora_handle => params[:q]) - webfinger(params[:q]) if people.empty? + Webfinger.in_background(params[:q]) if people.empty? else people = Person.search(params[:q], current_user) end @@ -131,7 +131,7 @@ class PeopleController < ApplicationController def retrieve_remote if params[:diaspora_handle] - webfinger(params[:diaspora_handle], :single_aspect_form => true) + Webfinger.in_background(params[:diaspora_handle], :single_aspect_form => true) render :nothing => true else render :nothing => true, :status => 422 @@ -161,7 +161,6 @@ class PeopleController < ApplicationController @contact = current_user.contact_for(@person) || Contact.new render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left'} end - Webfinger.new(account, opts) end def diaspora_id?(query) @@ -169,9 +168,6 @@ class PeopleController < ApplicationController end private - def webfinger(account, opts = {}) - Webfinger.new(account, opts) - end def remote_profile_with_no_user_session? @person && @person.remote? && !user_signed_in? diff --git a/app/models/jobs/fetch_webfinger.rb b/app/models/jobs/fetch_webfinger.rb new file mode 100644 index 000000000..0b4aec6d8 --- /dev/null +++ b/app/models/jobs/fetch_webfinger.rb @@ -0,0 +1,14 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'lib/webfinger' +module Jobs + class FetchWebfinger < Base + @queue = :socket_webfinger + + def self.perform(account) + Webfinger.new(account).fetch + end + end +end diff --git a/lib/webfinger.rb b/lib/webfinger.rb index d22f7aba0..975557b40 100644 --- a/lib/webfinger.rb +++ b/lib/webfinger.rb @@ -9,6 +9,10 @@ class Webfinger Rails.logger.info("event=webfinger status=initialized target=#{account}") end + def self.in_background(account, opts={}) + Resque.enqueue(Jobs::FetchWebfinger, account) + end + def fetch begin person = Person.by_account_identifier(@account) diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index e776a4eb5..332033cd8 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -385,11 +385,4 @@ describe PeopleController do @controller.diaspora_id?("ilya_2%3@joindiaspora.com").should be_false end end - - describe '#webfinger' do - it 'calls Webfinger.new' do - Webfinger.should_receive(:new).with(@user.diaspora_handle, anything).once - get :retrieve_remote, :diaspora_handle => @user.diaspora_handle - end - end end