Skip to content

Instantly share code, notes, and snippets.

@Neustrashimy
Last active June 27, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neustrashimy/7466d9500db792c423d4f85a0578f3d9 to your computer and use it in GitHub Desktop.
Save Neustrashimy/7466d9500db792c423d4f85a0578f3d9 to your computer and use it in GitHub Desktop.
Mastodon: Cleanup PreviewCards scripts for Rails Console
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.
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.
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