Last active
June 27, 2019 01:16
-
-
Save Neustrashimy/7466d9500db792c423d4f85a0578f3d9 to your computer and use it in GitHub Desktop.
Mastodon: Cleanup PreviewCards scripts for Rails Console
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
total_num = 0; 0 | |
total_size = 0; 0 | |
PreviewCard.where("updated_at < ?", 180.days.ago).find_each do |card| | |
total_num = total_num + 1 | |
if card.image_file_size != nil then | |
total_size = total_size + card.image_file_size | |
end | |
end; 0 | |
printf("found %d card(s), %d MBytes will reduced\n", total_num, total_size/1.megabytes) | |
# you can adjust check range in `where` cause. |
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
total_num = 0; 0 | |
total_size = 0; 0 | |
PreviewCard.where("updated_at < ?", 180.days.ago).find_each do |card| | |
total_num = total_num + 1 | |
if card.image_file_size != nil then | |
total_size = total_size + card.image_file_size | |
end | |
card.destroy! | |
end; 0 | |
printf("remove %d card(s), %d MBytes reduced\n", total_num, total_size/1.megabytes) | |
# you can adjust remove range in `where` cause. | |
# remove previewcard. | |
# Old (deleted) previewcards will not shown. | |
# If same url posted, Mastodon will fetch image and text for previewcard again. |
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
total_num = 0; 0 | |
total_size = 0; 0 | |
PreviewCard.where("updated_at < ?", 180.days.ago).find_each do |card| | |
total_num = total_num + 1 | |
if card.image_file_size != nil then | |
total_size = total_size + card.image_file_size | |
card.image.destroy! | |
card.save! | |
end | |
end; 0 | |
printf("found %d card(s), %d MBytes reduced\n", total_num, total_size/1.megabytes) | |
# you can adjust remove range in `where` cause. | |
# remove previewcard's image(s) only. | |
# If same url posted, Mastodon will not fetch previewcard's image again, but will shows cached previewcard (text only). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment