Merge remote-tracking branch 'parent/main' into upstream-20240913

This commit is contained in:
KMY 2024-09-13 10:31:48 +09:00
commit fc9d27ff91
392 changed files with 3757 additions and 3233 deletions

View file

@ -502,17 +502,7 @@ module Mastodon::CLI
- not muted/blocked by us
LONG_DESC
def prune
query = Account.remote.non_automated
query = query.where('NOT EXISTS (SELECT 1 FROM mentions WHERE account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM favourites WHERE account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM statuses WHERE account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM follows WHERE account_id = accounts.id OR target_account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM blocks WHERE account_id = accounts.id OR target_account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM mutes WHERE target_account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM reports WHERE target_account_id = accounts.id)')
query = query.where('NOT EXISTS (SELECT 1 FROM follow_requests WHERE account_id = accounts.id OR target_account_id = accounts.id)')
_, deleted = parallelize_with_progress(query) do |account|
_, deleted = parallelize_with_progress(prunable_accounts) do |account|
next if account.bot? || account.group?
next if account.suspended?
next if account.silenced?
@ -577,6 +567,31 @@ module Mastodon::CLI
private
def prunable_accounts
Account
.remote
.non_automated
.where.not(referencing_account(Mention, :account_id))
.where.not(referencing_account(Favourite, :account_id))
.where.not(referencing_account(Status, :account_id))
.where.not(referencing_account(Follow, :account_id))
.where.not(referencing_account(Follow, :target_account_id))
.where.not(referencing_account(Block, :account_id))
.where.not(referencing_account(Block, :target_account_id))
.where.not(referencing_account(Mute, :target_account_id))
.where.not(referencing_account(Report, :target_account_id))
.where.not(referencing_account(FollowRequest, :account_id))
.where.not(referencing_account(FollowRequest, :target_account_id))
end
def referencing_account(model, attribute)
model
.where(model.arel_table[attribute].eq Account.arel_table[:id])
.select(1)
.arel
.exists
end
def report_errors(errors)
message = errors.map do |error|
<<~STRING