闭社主体 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.

65 lines
2.2 KiB

  1. # frozen_string_literal: true
  2. namespace :mastodon do
  3. task make_admin: :environment do
  4. include RoutingHelper
  5. user = Account.find_local(ENV.fetch('USERNAME')).user
  6. user.update(admin: true)
  7. puts "Congrats! #{user.account.username} is now an admin. \\o/\nNavigate to #{admin_settings_url} to get started"
  8. end
  9. namespace :media do
  10. desc 'Removes media attachments that have not been assigned to any status for longer than a day'
  11. task clear: :environment do
  12. MediaAttachment.where(status_id: nil).where('created_at < ?', 1.day.ago).find_each(&:destroy)
  13. end
  14. desc 'Remove media attachments attributed to silenced accounts'
  15. task remove_silenced: :environment do
  16. MediaAttachment.where(account: Account.silenced).find_each(&:destroy)
  17. end
  18. end
  19. namespace :push do
  20. desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
  21. task clear: :environment do
  22. Account.remote.without_followers.where.not(subscription_expires_at: nil).find_each do |a|
  23. Rails.logger.debug "PuSH unsubscribing from #{a.acct}"
  24. UnsubscribeService.new.call(a)
  25. end
  26. end
  27. desc 'Re-subscribes to soon expiring PuSH subscriptions'
  28. task refresh: :environment do
  29. Account.expiring(1.day.from_now).find_each do |a|
  30. Rails.logger.debug "PuSH re-subscribing to #{a.acct}"
  31. SubscribeService.new.call(a)
  32. end
  33. end
  34. end
  35. namespace :feeds do
  36. desc 'Clear timelines of inactive users'
  37. task clear: :environment do
  38. User.confirmed.where('current_sign_in_at < ?', 14.days.ago).find_each do |user|
  39. Redis.current.del(FeedManager.instance.key(:home, user.account_id))
  40. end
  41. end
  42. desc 'Clears all timelines so that they would be regenerated on next hit'
  43. task clear_all: :environment do
  44. Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
  45. end
  46. end
  47. namespace :emails do
  48. desc 'Send out digest e-mails'
  49. task digest: :environment do
  50. User.confirmed.joins(:account).where(accounts: { silenced: false, suspended: false }).where('current_sign_in_at < ?', 20.days.ago).find_each do |user|
  51. DigestMailerWorker.perform_async(user.id)
  52. end
  53. end
  54. end
  55. end