Merge tag 'v3.3.0rc2'

This commit is contained in:
wuyingren 2020-12-19 11:26:05 +08:00
commit 49b73b1f65
307 changed files with 6877 additions and 1905 deletions

View file

@ -236,6 +236,25 @@ module Mastodon
say('OK', :green)
end
desc 'fix-duplicates', 'Find duplicate remote accounts and merge them'
option :dry_run, type: :boolean
long_desc <<-LONG_DESC
Merge known remote accounts sharing an ActivityPub actor identifier.
Such duplicates can occur when a remote server admin misconfigures their
domain configuration.
LONG_DESC
def fix_duplicates
Account.remote.select(:uri, 'count(*)').group(:uri).having('count(*) > 1').pluck_each(:uri) do |uri|
say("Duplicates found for #{uri}")
begin
ActivityPub::FetchRemotAccountService.new.call(uri) unless options[:dry_run]
rescue => e
say("Error processing #{uri}: #{e}", :red)
end
end
end
desc 'backup USERNAME', 'Request a backup for a user'
long_desc <<-LONG_DESC
Request a new backup for an account with a given USERNAME.

View file

@ -53,6 +53,8 @@ module Mastodon
custom_emojis_count = custom_emojis.count
custom_emojis.destroy_all unless options[:dry_run]
Instance.refresh unless options[:dry_run]
say("Removed #{custom_emojis_count} custom emojis", :green)
end
@ -83,7 +85,7 @@ module Mastodon
processed = Concurrent::AtomicFixnum.new(0)
failed = Concurrent::AtomicFixnum.new(0)
start_at = Time.now.to_f
seed = start ? [start] : Account.remote.domains
seed = start ? [start] : Instance.pluck(:domain)
blocked_domains = Regexp.new('\\.?' + DomainBlock.where(severity: 1).pluck(:domain).join('|') + '$')
progress = create_progress_bar

View file

@ -47,7 +47,7 @@ module Mastodon
ip_block ||= IpBlock.new(ip: address)
ip_block.severity = options[:severity]
ip_block.comment = options[:comment]
ip_block.comment = options[:comment] if options[:comment].present?
ip_block.expires_in = options[:duration]
if ip_block.save

View file

@ -14,7 +14,7 @@ module Mastodon
end
MIN_SUPPORTED_VERSION = 2019_10_01_213028
MAX_SUPPORTED_VERSION = 2020_10_17_234926
MAX_SUPPORTED_VERSION = 2020_12_18_054746
# Stubs to enjoy ActiveRecord queries while not depending on a particular
# version of the code/database
@ -55,8 +55,8 @@ module Mastodon
belongs_to :account, inverse_of: :account_stat
end
# Dummy class, to make migration possible across version changes
class Account < ApplicationRecord
# Dummy class, to make migration possible across version changes
has_one :user, inverse_of: :account
has_one :account_stat, inverse_of: :account
@ -69,6 +69,49 @@ module Mastodon
def acct
local? ? username : "#{username}@#{domain}"
end
# This is a duplicate of the AccountMerging concern because we need it to
# be independent from code version.
def merge_with!(other_account)
# Since it's the same remote resource, the remote resource likely
# already believes we are following/blocking, so it's safe to
# re-attribute the relationships too. However, during the presence
# of the index bug users could have *also* followed the reference
# account already, therefore mass update will not work and we need
# to check for (and skip past) uniqueness errors
owned_classes = [
Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite,
Follow, FollowRequest, Block, Mute, AccountIdentityProof,
AccountModerationNote, AccountPin, AccountStat, ListAccount,
PollVote, Mention
]
owned_classes << AccountDeletionRequest if ActiveRecord::Base.connection.table_exists?(:account_deletion_requests)
owned_classes << AccountNote if ActiveRecord::Base.connection.table_exists?(:account_notes)
owned_classes.each do |klass|
klass.where(account_id: other_account.id).find_each do |record|
begin
record.update_attribute(:account_id, id)
rescue ActiveRecord::RecordNotUnique
next
end
end
end
target_classes = [Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin]
target_classes << AccountNote if ActiveRecord::Base.connection.table_exists?(:account_notes)
target_classes.each do |klass|
klass.where(target_account_id: other_account.id).find_each do |record|
begin
record.update_attribute(:target_account_id, id)
rescue ActiveRecord::RecordNotUnique
next
end
end
end
end
end
class User < ApplicationRecord

View file

@ -17,7 +17,7 @@ module Mastodon
end
def flags
'rc1'
'rc2'
end
def suffix

View file

@ -39,6 +39,23 @@ module Paperclip
def default_url(style_name = default_style)
@url_generator.for_as_default(style_name)
end
STOPLIGHT_THRESHOLD = 10
STOPLIGHT_COOLDOWN = 30
# We overwrite this method to put a circuit breaker around
# calls to object storage, to stop hitting APIs that are slow
# to respond or don't respond at all and as such minimize the
# impact of object storage outages on application throughput
def save
Stoplight('object-storage') { super }.with_threshold(STOPLIGHT_THRESHOLD).with_cool_off_time(STOPLIGHT_COOLDOWN).with_error_handler do |error, handle|
if error.is_a?(Seahorse::Client::NetworkingError)
handle.call(error)
else
raise error
end
end.run
end
end
end