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

47 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. namespace :mastodon do
  3. namespace :media do
  4. desc 'Removes media attachments that have not been assigned to any status for longer than a day'
  5. task clear: :environment do
  6. MediaAttachment.where(status_id: nil).where('created_at < ?', 1.day.ago).find_each(&:destroy)
  7. end
  8. desc 'Remove media attachments attributed to silenced accounts'
  9. task remove_silenced: :environment do
  10. MediaAttachment.where(account: Account.silenced).find_each(&:destroy)
  11. end
  12. end
  13. namespace :push do
  14. desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
  15. task clear: :environment do
  16. Account.remote.without_followers.where.not(subscription_expires_at: nil).find_each do |a|
  17. Rails.logger.debug "PuSH unsubscribing from #{a.acct}"
  18. UnsubscribeService.new.call(a)
  19. end
  20. end
  21. desc 'Re-subscribes to soon expiring PuSH subscriptions'
  22. task refresh: :environment do
  23. Account.expiring(1.day.from_now).find_each do |a|
  24. Rails.logger.debug "PuSH re-subscribing to #{a.acct}"
  25. SubscribeService.new.call(a)
  26. end
  27. end
  28. end
  29. namespace :feeds do
  30. desc 'Clear timelines of inactive users'
  31. task clear: :environment do
  32. User.where('current_sign_in_at < ?', 14.days.ago).find_each do |user|
  33. Redis.current.del(FeedManager.instance.key(:home, user.account_id))
  34. end
  35. end
  36. desc 'Clears all timelines so that they would be regenerated on next hit'
  37. task clear_all: :environment do
  38. Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
  39. end
  40. end
  41. end