diff options
author | ThibG <thib@sitedethib.com> | 2019-12-19 16:07:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-19 16:07:21 +0100 |
commit | f064cd4fb8057af04f0f1db6a98fc45935811e25 (patch) | |
tree | 33375e965ba16e3491f3bc3cd733ff2331a48220 /lib | |
parent | 66ab1f83b0d342341181e0c88da83c966391fc0c (diff) | |
parent | dace054c0680b3ac6e0da31f3ffa501cd8840fbf (diff) |
Merge pull request #1255 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/statuses_cli.rb | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/mastodon/statuses_cli.rb b/lib/mastodon/statuses_cli.rb index eeedc026c..875183372 100644 --- a/lib/mastodon/statuses_cli.rb +++ b/lib/mastodon/statuses_cli.rb @@ -13,6 +13,7 @@ module Mastodon end option :days, type: :numeric, default: 90 + option :clean_followed, type: :boolean desc 'remove', 'Remove unreferenced statuses' long_desc <<~LONG_DESC Remove statuses that are not referenced by local user activity, such as @@ -20,7 +21,7 @@ module Mastodon by someone locally but no longer are. This is a computationally heavy procedure that creates extra database - indicides before commencing, and removes them afterward. + indices before commencing, and removes them afterward. LONG_DESC def remove say('Creating temporary database indices...') @@ -34,18 +35,28 @@ module Mastodon say('Beginning removal... This might take a while...') - Status.remote - .where('id < ?', max_id) - .where(reblog_of_id: nil) # Skip reblogs - .where(in_reply_to_id: nil) # Skip replies - .where('id NOT IN (SELECT status_pins.status_id FROM status_pins WHERE statuses.id = status_id)') # Skip statuses that are pinned on profiles - .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 - .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 - .where('id NOT IN (SELECT bookmarks.status_id FROM bookmarks WHERE statuses.id = bookmarks.status_id)') # Skip statuses bookmarked by local users - .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 - .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 - .in_batches - .delete_all + scope = Status.remote.where('id < ?', max_id) + # Skip reblogs of local statuses + 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))') + # 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)') + # Skip statuses that mention 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))') + # Skip statuses which have replies + scope = scope.where('id NOT IN (SELECT statuses1.in_reply_to_id FROM statuses AS statuses1 WHERE statuses.id = statuses1.in_reply_to_id)') + # Skip statuses reblogged by local accounts or with recent boosts + 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))') + # Skip statuses bookmarked by local users + scope = scope.where('id NOT IN (SELECT bookmarks.status_id FROM bookmarks WHERE statuses.id = bookmarks.status_id)') + + 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...') |