Extract method for account-referencing in CLI prune task (#31824)
Some checks failed
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled

This commit is contained in:
Matt Jankowski 2024-09-10 09:23:55 -04:00 committed by GitHub
parent da07adfe6c
commit c4b09d684e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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