The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
1.6 KiB

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