Get rid of all batch order warnings (#8334)

This commit is contained in:
Eugen Rochko 2018-08-21 12:25:50 +02:00 committed by GitHub
parent 83746b6364
commit d98de8ada7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 19 deletions

View file

@ -23,7 +23,7 @@ class Form::StatusBatch
media_attached_status_ids = MediaAttachment.where(status_id: status_ids).pluck(:status_id) media_attached_status_ids = MediaAttachment.where(status_id: status_ids).pluck(:status_id)
ApplicationRecord.transaction do ApplicationRecord.transaction do
Status.where(id: media_attached_status_ids).find_each do |status| Status.where(id: media_attached_status_ids).reorder(nil).find_each do |status|
status.update!(sensitive: sensitive) status.update!(sensitive: sensitive)
log_action :update, status log_action :update, status
end end
@ -35,7 +35,7 @@ class Form::StatusBatch
end end
def delete_statuses def delete_statuses
Status.where(id: status_ids).find_each do |status| Status.where(id: status_ids).reorder(nil).find_each do |status|
RemovalWorker.perform_async(status.id) RemovalWorker.perform_async(status.id)
log_action :destroy, status log_action :destroy, status
end end

View file

@ -15,13 +15,13 @@ class AfterBlockDomainFromAccountService < BaseService
private private
def reject_existing_followers! def reject_existing_followers!
@account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow| @account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).reorder(nil).find_each do |follow|
reject_follow!(follow) reject_follow!(follow)
end end
end end
def reject_pending_follow_requests! def reject_pending_follow_requests!
FollowRequest.where(target_account: @account).where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow_request| FollowRequest.where(target_account: @account).where(account: Account.where(domain: @domain)).includes(:account).reorder(nil).find_each do |follow_request|
reject_follow!(follow_request) reject_follow!(follow_request)
end end
end end

View file

@ -18,7 +18,7 @@ class BackupService < BaseService
def build_json! def build_json!
@collection = serialize(collection_presenter, ActivityPub::CollectionSerializer) @collection = serialize(collection_presenter, ActivityPub::CollectionSerializer)
account.statuses.with_includes.find_in_batches do |statuses| account.statuses.with_includes.reorder(nil).find_in_batches do |statuses|
statuses.each do |status| statuses.each do |status|
item = serialize(status, ActivityPub::ActivitySerializer) item = serialize(status, ActivityPub::ActivitySerializer)
item.delete(:'@context') item.delete(:'@context')
@ -60,7 +60,7 @@ class BackupService < BaseService
end end
def dump_media_attachments!(tar) def dump_media_attachments!(tar)
MediaAttachment.attached.where(account: account).find_in_batches do |media_attachments| MediaAttachment.attached.where(account: account).reorder(nil).find_in_batches do |media_attachments|
media_attachments.each do |m| media_attachments.each do |m|
download_to_tar(tar, m.file, m.file.path) download_to_tar(tar, m.file, m.file.path)
end end

View file

@ -43,14 +43,14 @@ class BlockDomainService < BaseService
end end
def suspend_accounts! def suspend_accounts!
blocked_domain_accounts.where(suspended: false).find_each do |account| blocked_domain_accounts.where(suspended: false).reorder(nil).find_each do |account|
UnsubscribeService.new.call(account) if account.subscribed? UnsubscribeService.new.call(account) if account.subscribed?
SuspendAccountService.new.call(account) SuspendAccountService.new.call(account)
end end
end end
def clear_account_images! def clear_account_images!
blocked_domain_accounts.find_each do |account| blocked_domain_accounts.reorder(nil).find_each do |account|
account.avatar.destroy if account.avatar.exists? account.avatar.destroy if account.avatar.exists?
account.header.destroy if account.header.exists? account.header.destroy if account.header.exists?
account.save account.save
@ -58,7 +58,7 @@ class BlockDomainService < BaseService
end end
def clear_account_attachments! def clear_account_attachments!
media_from_blocked_domain.find_each do |attachment| media_from_blocked_domain.reorder(nil).find_each do |attachment|
@affected_status_ids << attachment.status_id if attachment.status_id.present? @affected_status_ids << attachment.status_id if attachment.status_id.present?
attachment.file.destroy if attachment.file.exists? attachment.file.destroy if attachment.file.exists?

View file

@ -43,13 +43,13 @@ class RemoveStatusService < BaseService
end end
def remove_from_followers def remove_from_followers
@account.followers_for_local_distribution.find_each do |follower| @account.followers_for_local_distribution.reorder(nil).find_each do |follower|
FeedManager.instance.unpush_from_home(follower, @status) FeedManager.instance.unpush_from_home(follower, @status)
end end
end end
def remove_from_lists def remove_from_lists
@account.lists_for_local_distribution.select(:id, :account_id).find_each do |list| @account.lists_for_local_distribution.select(:id, :account_id).reorder(nil).find_each do |list|
FeedManager.instance.unpush_from_list(list, @status) FeedManager.instance.unpush_from_list(list, @status)
end end
end end

View file

@ -9,7 +9,7 @@ class RefollowWorker
target_account = Account.find(target_account_id) target_account = Account.find(target_account_id)
return unless target_account.protocol == :activitypub return unless target_account.protocol == :activitypub
target_account.followers.where(domain: nil).find_each do |follower| target_account.followers.where(domain: nil).reorder(nil).find_each do |follower|
# Locally unfollow remote account # Locally unfollow remote account
follower.unfollow!(target_account) follower.unfollow!(target_account)

View file

@ -6,7 +6,7 @@ class Scheduler::BackupCleanupScheduler
sidekiq_options unique: :until_executed sidekiq_options unique: :until_executed
def perform def perform
old_backups.find_each(&:destroy!) old_backups.reorder(nil).find_each(&:destroy!)
end end
private private

View file

@ -6,7 +6,7 @@ class Scheduler::EmailScheduler
sidekiq_options unique: :until_executed sidekiq_options unique: :until_executed
def perform def perform
eligible_users.find_each do |user| eligible_users.reorder(nil).find_each do |user|
next unless user.allows_digest_emails? next unless user.allows_digest_emails?
DigestMailerWorker.perform_async(user.id) DigestMailerWorker.perform_async(user.id)
end end

View file

@ -6,7 +6,7 @@ class Scheduler::UserCleanupScheduler
sidekiq_options unique: :until_executed sidekiq_options unique: :until_executed
def perform def perform
User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).find_in_batches do |batch| User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).reorder(nil).find_in_batches do |batch|
Account.where(id: batch.map(&:account_id)).delete_all Account.where(id: batch.map(&:account_id)).delete_all
User.where(id: batch.map(&:id)).delete_all User.where(id: batch.map(&:id)).delete_all
end end

View file

@ -503,7 +503,7 @@ namespace :mastodon do
desc 'Remove media attachments attributed to silenced accounts' desc 'Remove media attachments attributed to silenced accounts'
task remove_silenced: :environment do task remove_silenced: :environment do
nb_media_attachments = 0 nb_media_attachments = 0
MediaAttachment.where(account: Account.silenced).select(:id).find_in_batches do |media_attachments| MediaAttachment.where(account: Account.silenced).select(:id).reorder(nil).find_in_batches do |media_attachments|
nb_media_attachments += media_attachments.length nb_media_attachments += media_attachments.length
Maintenance::DestroyMediaWorker.push_bulk(media_attachments.map(&:id)) Maintenance::DestroyMediaWorker.push_bulk(media_attachments.map(&:id))
end end
@ -515,7 +515,7 @@ namespace :mastodon do
time_ago = ENV.fetch('NUM_DAYS') { 7 }.to_i.days.ago time_ago = ENV.fetch('NUM_DAYS') { 7 }.to_i.days.ago
nb_media_attachments = 0 nb_media_attachments = 0
MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).select(:id).find_in_batches do |media_attachments| MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).select(:id).reorder(nil).find_in_batches do |media_attachments|
nb_media_attachments += media_attachments.length nb_media_attachments += media_attachments.length
Maintenance::UncacheMediaWorker.push_bulk(media_attachments.map(&:id)) Maintenance::UncacheMediaWorker.push_bulk(media_attachments.map(&:id))
end end
@ -535,7 +535,7 @@ namespace :mastodon do
accounts = accounts.where(domain: ENV['DOMAIN']) if ENV['DOMAIN'].present? accounts = accounts.where(domain: ENV['DOMAIN']) if ENV['DOMAIN'].present?
nb_accounts = 0 nb_accounts = 0
accounts.select(:id).find_in_batches do |accounts_batch| accounts.select(:id).reorder(nil).find_in_batches do |accounts_batch|
nb_accounts += accounts_batch.length nb_accounts += accounts_batch.length
Maintenance::RedownloadAccountMediaWorker.push_bulk(accounts_batch.map(&:id)) Maintenance::RedownloadAccountMediaWorker.push_bulk(accounts_batch.map(&:id))
end end
@ -570,7 +570,7 @@ namespace :mastodon do
desc 'Generates home timelines for users who logged in in the past two weeks' desc 'Generates home timelines for users who logged in in the past two weeks'
task build: :environment do task build: :environment do
User.active.select(:id, :account_id).find_in_batches do |users| User.active.select(:id, :account_id).reorder(nil).find_in_batches do |users|
RegenerationWorker.push_bulk(users.map(&:account_id)) RegenerationWorker.push_bulk(users.map(&:account_id))
end end
end end