diff --git a/lib/mastodon/cli/statuses.rb b/lib/mastodon/cli/statuses.rb index 7104181e978..7188bc970ce 100644 --- a/lib/mastodon/cli/statuses.rb +++ b/lib/mastodon/cli/statuses.rb @@ -62,6 +62,8 @@ module Mastodon::CLI AND NOT EXISTS (SELECT 1 FROM mentions WHERE statuses.id = mentions.status_id AND mentions.account_id IN (SELECT accounts.id FROM accounts WHERE domain IS NULL)) AND NOT EXISTS (SELECT 1 FROM favourites WHERE statuses.id = favourites.status_id AND favourites.account_id IN (SELECT accounts.id FROM accounts WHERE domain IS NULL)) AND NOT EXISTS (SELECT 1 FROM bookmarks WHERE statuses.id = bookmarks.status_id AND bookmarks.account_id IN (SELECT accounts.id FROM accounts WHERE domain IS NULL)) + AND NOT EXISTS (SELECT 1 FROM quotes JOIN statuses statuses1 ON quotes.status_id = statuses1.id WHERE quotes.quoted_status_id = statuses.id AND (statuses1.uri IS NULL OR statuses1.local)) + AND NOT EXISTS (SELECT 1 FROM quotes JOIN statuses statuses1 ON quotes.quoted_status_id = statuses1.id WHERE quotes.status_id = statuses.id AND (statuses1.uri IS NULL OR statuses1.local)) #{clean_followed_sql} SQL diff --git a/spec/lib/mastodon/cli/statuses_spec.rb b/spec/lib/mastodon/cli/statuses_spec.rb index 2597ad7f274..5f0e6b952c5 100644 --- a/spec/lib/mastodon/cli/statuses_spec.rb +++ b/spec/lib/mastodon/cli/statuses_spec.rb @@ -15,6 +15,26 @@ RSpec.describe Mastodon::CLI::Statuses do describe '#remove', use_transactional_tests: false do let(:action) { :remove } + let(:local_account) { Fabricate(:account) } + let(:remote_account) { Fabricate(:account, domain: 'example.com') } + let(:followed_remote_account) { Fabricate(:account, domain: 'example.com') } + let!(:local_status) { Fabricate(:status, created_at: 1.year.ago) } + let!(:irrelevant_status) { Fabricate(:status, account: remote_account, created_at: 1.year.ago) } + let!(:followed_status) { Fabricate(:status, account: followed_remote_account, created_at: 1.year.ago) } + let!(:status_with_local_reply) { Fabricate(:status, account: remote_account, created_at: 1.year.ago) } + let!(:local_reply) { Fabricate(:status, thread: status_with_local_reply, created_at: 1.year.ago) } + let!(:irrelevant_quote) { Fabricate(:status, account: remote_account, created_at: 1.year.ago) } + let!(:quote_of_local) { Fabricate(:status, account: remote_account, created_at: 1.year.ago) } + let!(:quoted_by_local) { Fabricate(:status, account: remote_account, created_at: 1.year.ago) } + let!(:local_quote) { Fabricate(:status, created_at: 1.year.ago) } + + before do + local_account.follow!(followed_remote_account) + Fabricate(:quote, status: irrelevant_quote, quoted_status: irrelevant_status, state: :accepted) + Fabricate(:quote, status: quote_of_local, quoted_status: local_status, state: :accepted) + Fabricate(:quote, status: local_quote, quoted_status: quoted_by_local, state: :accepted) + end + context 'with small batch size' do let(:options) { { batch_size: 0 } } @@ -28,6 +48,10 @@ RSpec.describe Mastodon::CLI::Statuses do it 'removes unreferenced statuses' do expect { subject } .to output_results('Done after') + + expect(Status.all) + .to include(local_status, followed_status, local_reply, status_with_local_reply, quote_of_local, quoted_by_local, local_quote) + .and not_include(irrelevant_status, irrelevant_quote) end end end