Sometimes Mastodon loses link preview card images and never refetches them, espe...
Rolle Laukkarinen @rolle@mementomori.social
Sometimes Mastodon loses link preview card images and never refetches them, especially for older links. I haven't had time to figure out the root cause, so I created a quick cron script to fetch the missing images. Here it is, in case it's useful to anyone.
Edit: As it happens, the script dump repo is private, so here's the full script directly. It's Bash:
```
#!/bin/bash
# Re-fetch preview cards for recent local statuses with URLs but missing/broken cards.
# Runs as mastodon user via cron every 30 minutes.
cd /home/mastodon/live || exit 1
RAILS_ENV=production bin/rails runner '
cutoff = 6.hours.ago
Status.local
.where("created_at > ?", cutoff)
.where("text LIKE ?", "%https://%")
.order(id: :desc)
.limit(200)
.each do |status|
card = status.preview_card
next unless card.nil? || card.image_file_name.blank?
LinkCrawlWorker.perform_async(status.id)
end
'
```