diff options
author | takayamaki <fsgiko@gmail.com> | 2017-06-04 07:11:15 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-06-04 00:11:15 +0200 |
commit | 3eedad27375721aaaa6e8397124989e4ead771a9 (patch) | |
tree | 08d44ddfd6c217b9311efad92daf55328568cc82 /app | |
parent | ce7c0def88b4f9ee97913002fb2d41d1832bd8af (diff) |
change sidekiq queueing to bulk push (#3536)
Diffstat (limited to 'app')
4 files changed, 18 insertions, 9 deletions
diff --git a/app/controllers/settings/follower_domains_controller.rb b/app/controllers/settings/follower_domains_controller.rb index 13722345f..90b48887f 100644 --- a/app/controllers/settings/follower_domains_controller.rb +++ b/app/controllers/settings/follower_domains_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'sidekiq-bulk' + class Settings::FollowerDomainsController < ApplicationController layout 'admin' @@ -13,8 +15,8 @@ class Settings::FollowerDomainsController < ApplicationController def update domains = bulk_params[:select] || [] - domains.each do |domain| - SoftBlockDomainFollowersWorker.perform_async(current_account.id, domain) + SoftBlockDomainFollowersWorker.push_bulk(domains) do |domain| + [current_account.id, domain] end redirect_to settings_follower_domains_path, notice: I18n.t('followers.success', count: domains.size) diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 055fda8a9..3b74696d5 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'sidekiq-bulk' + class FanOutOnWriteService < BaseService # Push a status into home and mentions feeds # @param [Status] status @@ -34,8 +36,10 @@ class FanOutOnWriteService < BaseService def deliver_to_followers(status) Rails.logger.debug "Delivering status #{status.id} to followers" - status.account.followers.where(domain: nil).joins(:user).where('users.current_sign_in_at > ?', 14.days.ago).select(:id).reorder(nil).find_each do |follower| - FeedInsertWorker.perform_async(status.id, follower.id) + status.account.followers.where(domain: nil).joins(:user).where('users.current_sign_in_at > ?', 14.days.ago).select(:id).reorder(nil).find_in_batches do |followers| + FeedInsertWorker.push_bulk(followers) do |follower| + [status.id, follower.id] + end end end diff --git a/app/workers/scheduler/subscriptions_scheduler.rb b/app/workers/scheduler/subscriptions_scheduler.rb index 3ea3ad2b8..7bfd002f4 100644 --- a/app/workers/scheduler/subscriptions_scheduler.rb +++ b/app/workers/scheduler/subscriptions_scheduler.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true + require 'sidekiq-scheduler' +require 'sidekiq-bulk' class Scheduler::SubscriptionsScheduler include Sidekiq::Worker @@ -7,9 +9,7 @@ class Scheduler::SubscriptionsScheduler def perform logger.info 'Queueing PuSH re-subscriptions' - expiring_accounts.pluck(:id).each do |id| - Pubsubhubbub::SubscribeWorker.perform_async(id) - end + Pubsubhubbub::SubscribeWorker.push_bulk(expiring_accounts.pluck(:id)) end private diff --git a/app/workers/soft_block_domain_followers_worker.rb b/app/workers/soft_block_domain_followers_worker.rb index 2782d05d2..ce76683c5 100644 --- a/app/workers/soft_block_domain_followers_worker.rb +++ b/app/workers/soft_block_domain_followers_worker.rb @@ -1,13 +1,16 @@ # frozen_string_literal: true +require 'sidekiq-bulk' + class SoftBlockDomainFollowersWorker include Sidekiq::Worker sidekiq_options queue: 'pull' def perform(account_id, domain) - Account.find(account_id).followers.where(domain: domain).pluck(:id).each do |follower_id| - SoftBlockWorker.perform_async(account_id, follower_id) + followers_id = Account.find(account_id).followers.where(domain: domain).pluck(:id) + SoftBlockWorker.push_bulk(followers_id) do |follower_id| + [account_id, follower_id] end end end |