Skip to main content

Mastodon snippets

·426 words·2 mins

Very short und maybe a bit chaotic…

There are some style patches available for plain mastodon for those that would want to have a look at them.

Clear media files #

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export RAILS_ENV=production

exec > /home/mastodon/live/log/prune.log 2>&1

/home/mastodon/live/bin/tootctl statuses remove
/home/mastodon/live/bin/tootctl media remove --days=5
/home/mastodon/live/bin/tootctl media remove --prune-profiles --days=60
/home/mastodon/live/bin/tootctl preview_cards remove --days=15
/home/mastodon/live/bin/tootctl media remove-orphans
/home/mastodon/live/bin/tootctl cache clear
/home/mastodon/live/bin/tootctl media usage

Further removal of profile pics #

#!/usr/bin/env bash
# Kept only the accounts compression and jpeg optimization

cd /home/mastodon/live/public/system/cache
find -name '*.jpg' -print0 | xargs -0 jpegoptim --verbose --preserve --threshold=1 --max=45
find -name '*.jpeg' -print0 | xargs -0 jpegoptim --verbose --preserve --threshold=1 --max=45

cd /home/mastodon/live/public/system/cache/accounts
find -name '*.png' -print0 | xargs -0 pngquant --verbose --ext=.png --force --speed 10 --quality 45-50 --skip-if-larger

More snippets for use in the rails console #

Some or almost all of the following text is copy&paste’d from this issue at Github.

There are several scripts executable with RAILS_ENV=production bundle exec rails c, for convenience laid out here with minor corrections. Do not execute these without understanding what they do!:

Deleting all cached media attachments from external servers to allow web app to re-fetch them when they are queried. At least on my instance this is really slow, takes tens of seconds per attachment (is this the same as tootctl media remove?):

MediaAttachment.cached.where.not(remote_url: '').each do |attachment|

Deleting and re-downloading all cached remote emojis. This apparently has a problem that the local URLs for the cached emojis change, and the URLs aren’t updated to the fetched profile headers. I suppose this should be done before the next steps, assuming the cached local emoji URLs are set up correctly to the profile headers and names at the time of fetching. This doesn’t seem to work though, maybe tootctl emoji purge --remote-only would be better:

CustomEmoji.remote.where.not(image_file_name: nil).where.not(image_remote_url: '').each do |emoji|

Deleting all remote profile avatars, and re-fetching them. Are these two the same as tootctl accounts refresh --all?:

Account.remote.where.not(avatar_file_name: nil).where.not(avatar_remote_url: '').each do |a|

Deleting all remote profile headers, and re-fetching them. Hopefully this uses/updates the newly fetched local cached emoji URLs, and also includes the profile name as they often contain emojis:

Account.remote.where.not(header_file_name: nil).where.not(header_remote_url: '').each do |a|

It would be awesome to get tooling for these to tootctl. That said, I’m not entirely sure if destroying the entities is necessary before downloading them again, and perhaps we could use remove_entity_cache instead. I’m not very well acquainted with the codebase.