Solve `Abc/*` metrics for `db/*migrate*` files (#28568)

pull/28575/head
Matt Jankowski 1 year ago committed by GitHub
parent 74a0d81e90
commit 51d2b80ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -74,14 +74,12 @@ Metrics/ModuleLength:
Metrics/AbcSize: Metrics/AbcSize:
Exclude: Exclude:
- 'lib/mastodon/cli/*.rb' - 'lib/mastodon/cli/*.rb'
- db/*migrate/**/*
# Reason: Currently disabled in .rubocop_todo.yml # Reason: Currently disabled in .rubocop_todo.yml
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity # https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Exclude: Exclude:
- lib/mastodon/cli/*.rb - lib/mastodon/cli/*.rb
- db/*migrate/**/*
# Reason: # Reason:
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists

@ -77,90 +77,135 @@ class BackfillAdminActionLogs < ActiveRecord::Migration[6.1]
def up def up
safety_assured do safety_assured do
AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log| process_logs_for_account
next if log.account.nil? process_logs_for_user
process_logs_for_report
process_logs_for_domain_block
process_logs_for_domain_allow
process_logs_for_email_domain_block
process_logs_for_unavailable_domain
process_logs_for_status
process_logs_for_account_warning
process_logs_for_announcement
process_logs_for_ip_block
process_logs_for_custom_emoji
process_logs_for_canonical_email_block
process_logs_for_appeal
end
end
log.update_attribute('human_identifier', log.account.acct) def down; end
end
AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log| private
next if log.user.nil?
log.update_attribute('human_identifier', log.user.account.acct) def process_logs_for_account
log.update_attribute('route_param', log.user.account_id) AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log|
end next if log.account.nil?
AdminActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text') log.update_attribute('human_identifier', log.account.acct)
end
end
AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log| def process_logs_for_user
next if log.domain_block.nil? AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log|
next if log.user.nil?
log.update_attribute('human_identifier', log.domain_block.domain) log.update_attribute('human_identifier', log.user.account.acct)
end log.update_attribute('route_param', log.user.account_id)
end
end
AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log| def process_logs_for_report
next if log.domain_allow.nil? AdminActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text')
end
log.update_attribute('human_identifier', log.domain_allow.domain) def process_logs_for_domain_block
end AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log|
next if log.domain_block.nil?
AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log| log.update_attribute('human_identifier', log.domain_block.domain)
next if log.email_domain_block.nil? end
end
log.update_attribute('human_identifier', log.email_domain_block.domain) def process_logs_for_domain_allow
end AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log|
next if log.domain_allow.nil?
AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log| log.update_attribute('human_identifier', log.domain_allow.domain)
next if log.unavailable_domain.nil? end
end
log.update_attribute('human_identifier', log.unavailable_domain.domain) def process_logs_for_email_domain_block
end AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log|
next if log.email_domain_block.nil?
AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.email_domain_block.domain)
next if log.status.nil? end
end
log.update_attribute('human_identifier', log.status.account.acct) def process_logs_for_unavailable_domain
log.update_attribute('permalink', log.status.uri) AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log|
end next if log.unavailable_domain.nil?
AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.unavailable_domain.domain)
next if log.account_warning.nil? end
end
log.update_attribute('human_identifier', log.account_warning.account.acct) def process_logs_for_status
end AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log|
next if log.status.nil?
AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.status.account.acct)
next if log.announcement.nil? log.update_attribute('permalink', log.status.uri)
end
end
log.update_attribute('human_identifier', log.announcement.text) def process_logs_for_account_warning
end AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log|
next if log.account_warning.nil?
AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.account_warning.account.acct)
next if log.ip_block.nil? end
end
log.update_attribute('human_identifier', "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}") def process_logs_for_announcement
end AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log|
next if log.announcement.nil?
AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.announcement.text)
next if log.custom_emoji.nil? end
end
log.update_attribute('human_identifier', log.custom_emoji.shortcode) def process_logs_for_ip_block
end AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log|
next if log.ip_block.nil?
AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}")
next if log.canonical_email_block.nil? end
end
log.update_attribute('human_identifier', log.canonical_email_block.canonical_email_hash) def process_logs_for_custom_emoji
end AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log|
next if log.custom_emoji.nil?
AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.custom_emoji.shortcode)
next if log.appeal.nil? end
end
log.update_attribute('human_identifier', log.appeal.account.acct) def process_logs_for_canonical_email_block
log.update_attribute('route_param', log.appeal.account_warning_id) AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log|
end next if log.canonical_email_block.nil?
log.update_attribute('human_identifier', log.canonical_email_block.canonical_email_hash)
end end
end end
def down; end def process_logs_for_appeal
AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log|
next if log.appeal.nil?
log.update_attribute('human_identifier', log.appeal.account.acct)
log.update_attribute('route_param', log.appeal.account_warning_id)
end
end
end end

@ -77,90 +77,135 @@ class BackfillAdminActionLogsAgain < ActiveRecord::Migration[6.1]
def up def up
safety_assured do safety_assured do
AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log| process_logs_for_account
next if log.account.nil? process_logs_for_user
process_logs_for_report
process_logs_for_domain_block
process_logs_for_domain_allow
process_logs_for_email_domain_block
process_logs_for_unavailable_domain
process_logs_for_status
process_logs_for_account_warning
process_logs_for_announcement
process_logs_for_ip_block
process_logs_for_custom_emoji
process_logs_for_canonical_email_block
process_logs_for_appeal
end
end
log.update_attribute('human_identifier', log.account.acct) def down; end
end
AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log| private
next if log.user.nil?
log.update_attribute('human_identifier', log.user.account.acct) def process_logs_for_account
log.update_attribute('route_param', log.user.account_id) AdminActionLog.includes(:account).where(target_type: 'Account', human_identifier: nil).find_each do |log|
end next if log.account.nil?
AdminActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text') log.update_attribute('human_identifier', log.account.acct)
end
end
AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log| def process_logs_for_user
next if log.domain_block.nil? AdminActionLog.includes(user: :account).where(target_type: 'User', human_identifier: nil).find_each do |log|
next if log.user.nil?
log.update_attribute('human_identifier', log.domain_block.domain) log.update_attribute('human_identifier', log.user.account.acct)
end log.update_attribute('route_param', log.user.account_id)
end
end
AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log| def process_logs_for_report
next if log.domain_allow.nil? AdminActionLog.where(target_type: 'Report', human_identifier: nil).in_batches.update_all('human_identifier = target_id::text')
end
log.update_attribute('human_identifier', log.domain_allow.domain) def process_logs_for_domain_block
end AdminActionLog.includes(:domain_block).where(target_type: 'DomainBlock').find_each do |log|
next if log.domain_block.nil?
AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log| log.update_attribute('human_identifier', log.domain_block.domain)
next if log.email_domain_block.nil? end
end
log.update_attribute('human_identifier', log.email_domain_block.domain) def process_logs_for_domain_allow
end AdminActionLog.includes(:domain_allow).where(target_type: 'DomainAllow').find_each do |log|
next if log.domain_allow.nil?
AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log| log.update_attribute('human_identifier', log.domain_allow.domain)
next if log.unavailable_domain.nil? end
end
log.update_attribute('human_identifier', log.unavailable_domain.domain) def process_logs_for_email_domain_block
end AdminActionLog.includes(:email_domain_block).where(target_type: 'EmailDomainBlock').find_each do |log|
next if log.email_domain_block.nil?
AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.email_domain_block.domain)
next if log.status.nil? end
end
log.update_attribute('human_identifier', log.status.account.acct) def process_logs_for_unavailable_domain
log.update_attribute('permalink', log.status.uri) AdminActionLog.includes(:unavailable_domain).where(target_type: 'UnavailableDomain').find_each do |log|
end next if log.unavailable_domain.nil?
AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.unavailable_domain.domain)
next if log.account_warning.nil? end
end
log.update_attribute('human_identifier', log.account_warning.account.acct) def process_logs_for_status
end AdminActionLog.includes(status: :account).where(target_type: 'Status', human_identifier: nil).find_each do |log|
next if log.status.nil?
AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.status.account.acct)
next if log.announcement.nil? log.update_attribute('permalink', log.status.uri)
end
end
log.update_attribute('human_identifier', log.announcement.text) def process_logs_for_account_warning
end AdminActionLog.includes(account_warning: :account).where(target_type: 'AccountWarning', human_identifier: nil).find_each do |log|
next if log.account_warning.nil?
AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.account_warning.account.acct)
next if log.ip_block.nil? end
end
log.update_attribute('human_identifier', "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}") def process_logs_for_announcement
end AdminActionLog.includes(:announcement).where(target_type: 'Announcement', human_identifier: nil).find_each do |log|
next if log.announcement.nil?
AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.announcement.text)
next if log.custom_emoji.nil? end
end
log.update_attribute('human_identifier', log.custom_emoji.shortcode) def process_logs_for_ip_block
end AdminActionLog.includes(:ip_block).where(target_type: 'IpBlock', human_identifier: nil).find_each do |log|
next if log.ip_block.nil?
AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', "#{log.ip_block.ip}/#{log.ip_block.ip.prefix}")
next if log.canonical_email_block.nil? end
end
log.update_attribute('human_identifier', log.canonical_email_block.canonical_email_hash) def process_logs_for_custom_emoji
end AdminActionLog.includes(:custom_emoji).where(target_type: 'CustomEmoji', human_identifier: nil).find_each do |log|
next if log.custom_emoji.nil?
AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log| log.update_attribute('human_identifier', log.custom_emoji.shortcode)
next if log.appeal.nil? end
end
log.update_attribute('human_identifier', log.appeal.account.acct) def process_logs_for_canonical_email_block
log.update_attribute('route_param', log.appeal.account_warning_id) AdminActionLog.includes(:canonical_email_block).where(target_type: 'CanonicalEmailBlock', human_identifier: nil).find_each do |log|
end next if log.canonical_email_block.nil?
log.update_attribute('human_identifier', log.canonical_email_block.canonical_email_hash)
end end
end end
def down; end def process_logs_for_appeal
AdminActionLog.includes(appeal: :account).where(target_type: 'Appeal', human_identifier: nil).find_each do |log|
next if log.appeal.nil?
log.update_attribute('human_identifier', log.appeal.account.acct)
log.update_attribute('route_param', log.appeal.account_warning_id)
end
end
end end

Loading…
Cancel
Save