-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Add tootctl preview_cards remove
#11320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Gargron
merged 5 commits into
mastodon:master
from
mayaeh:feature_tootctl_preview_cards
Jul 28, 2019
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a4d4dd5
Add `tootctl preview_cards remove`
mayaeh 09d153f
fix code style
mayaeh 015bd00
Remove `Scheduler::PreviewCardsCleanupScheduler` file
mayaeh decc0c3
fix code style again
mayaeh a3045ef
Added a function to output confirmation if the specified number of da…
mayaeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../../config/boot' | ||
| require_relative '../../config/environment' | ||
| require_relative 'cli_helper' | ||
|
|
||
| module Mastodon | ||
| class PreviewCardsCLI < Thor | ||
| include ActionView::Helpers::NumberHelper | ||
|
|
||
| def self.exit_on_failure? | ||
| true | ||
| end | ||
|
|
||
| option :days, type: :numeric, default: 180 | ||
| option :background, type: :boolean, default: false | ||
| option :verbose, type: :boolean, default: false | ||
| option :dry_run, type: :boolean, default: false | ||
| option :link, type: :boolean, default: false | ||
| desc 'remove', 'Remove preview cards' | ||
| long_desc <<-DESC | ||
| Removes locally thumbnails for previews. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does |
||
|
|
||
| The --days option specifies how old preview cards have to be before | ||
| they are removed. It defaults to 180 days. | ||
|
|
||
| With the --background option, instead of deleting the files sequentially, | ||
| they will be queued into Sidekiq and the command will exit as soon as | ||
| possible. In Sidekiq they will be processed with higher concurrency, but | ||
| it may impact other operations of the Mastodon server, and it may overload | ||
| the underlying file storage. | ||
|
|
||
| With the --dry-run option, no work will be done. | ||
|
|
||
| With the --verbose option, when preview cards are processed sequentially in the | ||
| foreground, the IDs of the preview cards will be printed. | ||
|
|
||
| With the --link option, delete only link-type preview cards. | ||
| DESC | ||
| def remove | ||
| time_ago = options[:days].days.ago | ||
| queued = 0 | ||
| processed = 0 | ||
| size = 0 | ||
| dry_run = options[:dry_run] ? '(DRY RUN)' : '' | ||
|
|
||
| if options[:link] && options[:background] | ||
|
mayaeh marked this conversation as resolved.
Outdated
|
||
| PreviewCard.where.not(image_file_name: nil).where(type: :link).where('updated_at < ?', time_ago).select(:id, :image_file_size).reorder(nil).find_in_batches do |preview_cards| | ||
| queued += preview_cards.size | ||
| size += preview_cards.reduce(0) { |sum, p| sum + (p.image_file_size || 0) } | ||
| Maintenance::UncachePreviewWorker.push_bulk(preview_cards.map(&:id)) unless options[:dry_run] | ||
| end | ||
|
|
||
| elsif options[:link] && !options[:background] | ||
| PreviewCard.where.not(image_file_name: nil).where(type: :link).where('updated_at < ?', time_ago).select(:id, :image_file_size).reorder(nil).find_in_batches do |preview_cards| | ||
| preview_cards.each do |p| | ||
| size += p.image_file_size || 0 | ||
| Maintenance::UncachePreviewWorker.new.perform(p.id) unless options[:dry_run] | ||
| options[:verbose] ? say(p.id) : say('.', :green, false) | ||
| processed += 1 | ||
| end | ||
| end | ||
|
|
||
| elsif !options[:link] && options[:background] | ||
| PreviewCard.where.not(image_file_name: nil).where('updated_at < ?', time_ago).select(:id, :image_file_size).reorder(nil).find_in_batches do |preview_cards| | ||
| queued += preview_cards.size | ||
| size += preview_cards.reduce(0) { |sum, p| sum + (p.image_file_size || 0) } | ||
| Maintenance::UncachePreviewWorker.push_bulk(preview_cards.map(&:id)) unless options[:dry_run] | ||
| end | ||
|
|
||
| else | ||
| PreviewCard.where.not(image_file_name: nil).where('updated_at < ?', time_ago).select(:id, :image_file_size).reorder(nil).find_in_batches do |preview_cards| | ||
| preview_cards.each do |p| | ||
| size += p.image_file_size || 0 | ||
| Maintenance::UncachePreviewWorker.new.perform(p.id) unless options[:dry_run] | ||
| options[:verbose] ? say(p.id) : say('.', :green, false) | ||
| processed += 1 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| say | ||
|
|
||
| if options[:background] | ||
| say("Scheduled the deletion of #{queued} preview cards (approx. #{number_to_human_size(size)}) #{dry_run}", :green, true) | ||
| else | ||
| say("Removed #{processed} preview cards (approx. #{number_to_human_size(size)}) #{dry_run}", :green, true) | ||
| end | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.