diff --git a/app/jobs/base.rb b/app/jobs/base.rb index cd0e35e74e0..4158825c8dd 100644 --- a/app/jobs/base.rb +++ b/app/jobs/base.rb @@ -244,21 +244,25 @@ module Jobs def self.scheduled_for(job_name, params={}) params = params.with_indifferent_access job_class = "Jobs::#{job_name.to_s.camelcase}" - Sidekiq::ScheduledSet.new.select do |scheduled_job| - if scheduled_job.klass.to_s == job_class - matched = true - job_params = scheduled_job.item["args"][0].with_indifferent_access - params.each do |key, value| - if job_params[key] != value - matched = false - break + + scheduled_jobs = [] + Sidekiq::Queue.all.each do |queue| + queue.each do |scheduled_job| + if scheduled_job.klass.to_s == job_class + matched = true + job_params = scheduled_job.item["args"][0].with_indifferent_access + params.each do |key, value| + if job_params[key] != value + matched = false + break + end end + scheduled_jobs << scheduled_job if matched end - matched - else - false end end + + scheduled_jobs end end diff --git a/app/jobs/scheduled/create_missing_avatars.rb b/app/jobs/scheduled/create_missing_avatars.rb index 8526b411553..eade6d6ad40 100644 --- a/app/jobs/scheduled/create_missing_avatars.rb +++ b/app/jobs/scheduled/create_missing_avatars.rb @@ -7,9 +7,10 @@ module Jobs UserAvatar.includes(:user) .where(last_gravatar_download_attempt: nil) .order("users.last_posted_at DESC") - .limit(5000) - .each do |u| - u.user.refresh_avatar + .find_in_batches(batch_size: 5000) do |user_avatars| + user_avatars.each do |user_avatar| + user_avatar.user.refresh_avatar + end end end end diff --git a/app/models/user.rb b/app/models/user.rb index f12643e06c4..b412de9dc79 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -753,6 +753,7 @@ class User < ActiveRecord::Base avatar = user_avatar || create_user_avatar if SiteSetting.automatically_download_gravatars? && !avatar.last_gravatar_download_attempt + Jobs.cancel_scheduled_job(:update_gravatar, user_id: self.id, avatar_id: avatar.id) Jobs.enqueue(:update_gravatar, user_id: self.id, avatar_id: avatar.id) end