闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

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