feeds_cli.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. require_relative '../../config/boot'
  3. require_relative '../../config/environment'
  4. require_relative 'cli_helper'
  5. module Mastodon
  6. class FeedsCLI < Thor
  7. include CLIHelper
  8. include Redisable
  9. def self.exit_on_failure?
  10. true
  11. end
  12. option :all, type: :boolean, default: false
  13. option :concurrency, type: :numeric, default: 5, aliases: [:c]
  14. option :verbose, type: :boolean, aliases: [:v]
  15. option :dry_run, type: :boolean, default: false
  16. desc 'build [USERNAME]', 'Build home and list feeds for one or all users'
  17. long_desc <<-LONG_DESC
  18. Build home and list feeds that are stored in Redis from the database.
  19. With the --all option, all active users will be processed.
  20. Otherwise, a single user specified by USERNAME.
  21. LONG_DESC
  22. def build(username = nil)
  23. dry_run = options[:dry_run] ? '(DRY RUN)' : ''
  24. if options[:all] || username.nil?
  25. processed, = parallelize_with_progress(Account.joins(:user).merge(User.active)) do |account|
  26. PrecomputeFeedService.new.call(account) unless options[:dry_run]
  27. end
  28. say("Regenerated feeds for #{processed} accounts #{dry_run}", :green, true)
  29. elsif username.present?
  30. account = Account.find_local(username)
  31. if account.nil?
  32. say('No such account', :red)
  33. exit(1)
  34. end
  35. PrecomputeFeedService.new.call(account) unless options[:dry_run]
  36. say("OK #{dry_run}", :green, true)
  37. else
  38. say('No account(s) given', :red)
  39. exit(1)
  40. end
  41. end
  42. desc 'clear', 'Remove all home and list feeds from Redis'
  43. def clear
  44. keys = redis.keys('feed:*')
  45. redis.pipelined do
  46. keys.each { |key| redis.del(key) }
  47. end
  48. say('OK', :green)
  49. end
  50. end
  51. end