The code powering m.abunchtell.com https://m.abunchtell.com
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

58 linhas
2.0 KiB

  1. # frozen_string_literal: true
  2. require_relative '../../config/boot'
  3. require_relative '../../config/environment'
  4. require_relative 'cli_helper'
  5. # rubocop:disable Rails/Output
  6. module Mastodon
  7. class MediaCLI < Thor
  8. option :days, type: :numeric, default: 7
  9. option :background, type: :boolean, default: false
  10. desc 'remove', 'Remove remote media files'
  11. long_desc <<-DESC
  12. Removes locally cached copies of media attachments from other servers.
  13. The --days option specifies how old media attachments have to be before
  14. they are removed. It defaults to 7 days.
  15. With the --background option, instead of deleting the files sequentially,
  16. they will be queued into Sidekiq and the command will exit as soon as
  17. possible. In Sidekiq they will be processed with higher concurrency, but
  18. it may impact other operations of the Mastodon server, and it may overload
  19. the underlying file storage.
  20. DESC
  21. def remove
  22. time_ago = options[:days].days.ago
  23. queued = 0
  24. processed = 0
  25. if options[:background]
  26. MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).select(:id).reorder(nil).find_in_batches do |media_attachments|
  27. queued += media_attachments.size
  28. Maintenance::UncacheMediaWorker.push_bulk(media_attachments.map(&:id))
  29. end
  30. else
  31. MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).reorder(nil).find_in_batches do |media_attachments|
  32. media_attachments.each do |m|
  33. Maintenance::UncacheMediaWorker.new.perform(m)
  34. say('.', :green, false)
  35. processed += 1
  36. end
  37. end
  38. end
  39. say
  40. if options[:background]
  41. say("Scheduled the deletion of #{queued} media attachments", :green)
  42. else
  43. say("Removed #{processed} media attachments", :green)
  44. end
  45. end
  46. end
  47. end
  48. # rubocop:enable Rails/Output