Last active
February 4, 2018 18:12
-
-
Save MitarashiDango/6b068f804ecbc28dae3f865f2ef2de83 to your computer and use it in GitHub Desktop.
お気に入りされてない7日以上前のリモートメディアキャッシュを削除するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
time_ago = ENV.fetch('NUM_DAYS') { 7 }.to_i.days.ago | |
MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).find_each do |media| | |
if Account.where(id: Favourite.select('account_id').where(status_id: media.status_id)).where(domain: nil).count == 0 | |
media.file.destroy | |
media.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
現行の remote_remote タスクは、リモートメディアキャッシュを削除してもインスタンス内でトゥートが参照された場合、再度メディアデータを取得しようとします。
しかし、取得先のアカウントやトゥートが削除されていた場合は当然取得できません。
このスクリプトでは、削除時にインスタンス内のアカウントがお気に入り登録しているかをチェックし、お気に入りされていないリモートメディアキャッシュを削除する動作となっており、再取得に失敗してメディアが永久的に見られなくなることを防止します。