Skip to content

Instantly share code, notes, and snippets.

@Neustrashimy Neustrashimy/calc_only.rb
Last active Jun 27, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.