forked from treehouse/mastodon
Changes to tootctl statuses remove (#11267)
* Fix comments in statuses_cli The comment for the part of query keeping statuses which have replies was incorrect, explaining the part of the query kept favourited statuses instead * Keep statuses favourited by local users in tootctl statuses remove * Do delete old replies that are not direct interactions with local users * Skip reblogs of local statuses instead of all reblogs * Optimize some queries * Keep old statuses with recent reblogs * Add option to clear toots from followed accounts toosignup-info-prompt
parent
2ee5a9d9c3
commit
7fe45e7c03
|
@ -13,6 +13,7 @@ module Mastodon
|
||||||
end
|
end
|
||||||
|
|
||||||
option :days, type: :numeric, default: 90
|
option :days, type: :numeric, default: 90
|
||||||
|
option :clean_followed, type: :boolean
|
||||||
desc 'remove', 'Remove unreferenced statuses'
|
desc 'remove', 'Remove unreferenced statuses'
|
||||||
long_desc <<~LONG_DESC
|
long_desc <<~LONG_DESC
|
||||||
Remove statuses that are not referenced by local user activity, such as
|
Remove statuses that are not referenced by local user activity, such as
|
||||||
|
@ -34,17 +35,26 @@ module Mastodon
|
||||||
|
|
||||||
say('Beginning removal... This might take a while...')
|
say('Beginning removal... This might take a while...')
|
||||||
|
|
||||||
Status.remote
|
scope = Status.remote.where('id < ?', max_id)
|
||||||
.where('id < ?', max_id)
|
# Skip reblogs of local statuses
|
||||||
.where(reblog_of_id: nil) # Skip reblogs
|
scope = scope.where('reblog_of_id NOT IN (SELECT statuses1.id FROM statuses AS statuses1 WHERE statuses1.id = statuses.reblog_of_id AND (statuses1.uri IS NULL OR statuses1.local))')
|
||||||
.where(in_reply_to_id: nil) # Skip replies
|
# Skip statuses that are pinned on profiles
|
||||||
.where('id NOT IN (SELECT status_pins.status_id FROM status_pins WHERE statuses.id = status_id)') # Skip statuses that are pinned on profiles
|
scope = scope.where('id NOT IN (SELECT status_pins.status_id FROM status_pins WHERE statuses.id = status_id)')
|
||||||
.where('id NOT IN (SELECT mentions.status_id FROM mentions WHERE statuses.id = mentions.status_id AND mentions.account_id IN (SELECT accounts.id FROM accounts WHERE domain IS NULL))') # Skip statuses that mention local accounts
|
# Skip statuses that mention local accounts
|
||||||
.where('id NOT IN (SELECT statuses1.in_reply_to_id FROM statuses AS statuses1 WHERE statuses.id = statuses1.in_reply_to_id)') # Skip statuses favourited by local accounts
|
scope = scope.where('id NOT IN (SELECT mentions.status_id FROM mentions WHERE statuses.id = mentions.status_id AND mentions.account_id IN (SELECT accounts.id FROM accounts WHERE domain IS NULL))')
|
||||||
.where('id NOT IN (SELECT statuses1.reblog_of_id FROM statuses AS statuses1 WHERE statuses.id = statuses1.reblog_of_id AND statuses1.account_id IN (SELECT accounts.id FROM accounts WHERE accounts.domain IS NULL))') # Skip statuses reblogged by local accounts
|
# Skip statuses which have replies
|
||||||
.where('account_id NOT IN (SELECT follows.target_account_id FROM follows WHERE statuses.account_id = follows.target_account_id)') # Skip accounts followed by local accounts
|
scope = scope.where('id NOT IN (SELECT statuses1.in_reply_to_id FROM statuses AS statuses1 WHERE statuses.id = statuses1.in_reply_to_id)')
|
||||||
.in_batches
|
# Skip statuses reblogged by local accounts or with recent boosts
|
||||||
.delete_all
|
scope = scope.where('id NOT IN (SELECT statuses1.reblog_of_id FROM statuses AS statuses1 WHERE statuses.id = statuses1.reblog_of_id AND (statuses1.uri IS NULL OR statuses1.local OR statuses1.id >= ?))', max_id)
|
||||||
|
# Skip statuses favourited by local users
|
||||||
|
scope = scope.where('id NOT IN (SELECT favourites.status_id FROM favourites WHERE statuses.id = favourites.status_id AND favourites.account_id IN (SELECT accounts.id FROM accounts WHERE domain IS NULL))')
|
||||||
|
|
||||||
|
unless options[:clean_followed]
|
||||||
|
# Skip accounts followed by local accounts
|
||||||
|
scope = scope.where('account_id NOT IN (SELECT follows.target_account_id FROM follows WHERE statuses.account_id = follows.target_account_id)')
|
||||||
|
end
|
||||||
|
|
||||||
|
scope.in_batches.delete_all
|
||||||
|
|
||||||
say('Beginning removal of now-orphaned media attachments to free up disk space...')
|
say('Beginning removal of now-orphaned media attachments to free up disk space...')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue