Move PubSubHubbub pinging to a background worker

It can take as much as 0.5s if not longer to complete
This commit is contained in:
Eugen Rochko 2016-10-05 13:50:21 +02:00
parent 2febc6ed65
commit 3319473b2c
5 changed files with 13 additions and 4 deletions

View File

@ -5,7 +5,7 @@ class FavouriteService < BaseService
# @return [Favourite] # @return [Favourite]
def call(account, status) def call(account, status)
favourite = Favourite.create!(account: account, status: status) favourite = Favourite.create!(account: account, status: status)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url]) HubPingWorker.perform_async(account.id)
if status.local? if status.local?
NotificationMailer.favourite(status, account).deliver_later unless status.account.blocking?(account) NotificationMailer.favourite(status, account).deliver_later unless status.account.blocking?(account)

View File

@ -17,7 +17,7 @@ class FollowService < BaseService
end end
merge_into_timeline(target_account, source_account) merge_into_timeline(target_account, source_account)
source_account.ping!(account_url(source_account, format: 'atom'), [Rails.configuration.x.hub_url]) HubPingWorker.perform_async(source_account.id)
follow follow
end end

View File

@ -10,7 +10,7 @@ class PostStatusService < BaseService
attach_media(status, media_ids) attach_media(status, media_ids)
process_mentions_service.call(status) process_mentions_service.call(status)
DistributionWorker.perform_async(status.id) DistributionWorker.perform_async(status.id)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url]) HubPingWorker.perform_async(account.id)
status status
end end

View File

@ -6,7 +6,7 @@ class ReblogService < BaseService
def call(account, reblogged_status) def call(account, reblogged_status)
reblog = account.statuses.create!(reblog: reblogged_status, text: '') reblog = account.statuses.create!(reblog: reblogged_status, text: '')
DistributionWorker.perform_async(reblog.id) DistributionWorker.perform_async(reblog.id)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url]) HubPingWorker.perform_async(account.id)
if reblogged_status.local? if reblogged_status.local?
NotificationMailer.reblog(reblogged_status, account).deliver_later unless reblogged_status.account.blocking?(account) NotificationMailer.reblog(reblogged_status, account).deliver_later unless reblogged_status.account.blocking?(account)

View File

@ -0,0 +1,9 @@
class HubPingWorker
include Sidekiq::Worker
include RoutingHelper
def perform(account_id)
account = Account.find(account_id)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
end
end