mastodon.rake 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. end
  9. namespace :push do
  10. desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
  11. task clear: :environment do
  12. Account.remote.without_followers.where.not(subscription_expires_at: nil).find_each do |a|
  13. Rails.logger.debug "PuSH unsubscribing from #{a.acct}"
  14. UnsubscribeService.new.call(a)
  15. end
  16. end
  17. desc 'Re-subscribes to soon expiring PuSH subscriptions'
  18. task refresh: :environment do
  19. Account.expiring(1.day.from_now).find_each do |a|
  20. Rails.logger.debug "PuSH re-subscribing to #{a.acct}"
  21. SubscribeService.new.call(a)
  22. end
  23. end
  24. end
  25. namespace :feeds do
  26. desc 'Clear timelines of inactive users'
  27. task clear: :environment do
  28. User.where('current_sign_in_at < ?', 14.days.ago).find_each do |user|
  29. Redis.current.del(FeedManager.instance.key(:home, user.account_id))
  30. Redis.current.del(FeedManager.instance.key(:mentions, user.account_id))
  31. end
  32. end
  33. desc 'Clears all timelines so that they would be regenerated on next hit'
  34. task clear_all: :environment do
  35. Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
  36. end
  37. end
  38. end