Ballooning Avatars and Headers folders

There’s been a few posts here in the past on this (like this one), but since the system locks them after inactivity I can’t revive discussion on the topic, but the gist of this issue is that system/accounts/avatars and system/accounts/headers are gigantic in size on my server which is just a single user instance because Mastodon doesn’t remove old avatars and headers when removing old media with the tootctl command. This is a problem because the folder will forever get bigger and bigger without a way to remove old images.

There is an open issue for this, but what I’m asking here is if there’s a way for me to get rid of old ones manually without breaking Mastodon? Because if I just delete images from the folders I’d end up with a bunch of broken images in Mastodon. Eventually pretty soon these folders are going to get too big.

This Old Guide has task for re downloading the avatar/Header so we can still do that althouch cmd are changed so you can delete the folder and Re download the images

Thanks. Yeah, I remember the old command for redownloading the avatars as I was having difficulty with it after a server migration, but tootctl doesn’t have an equivalent. The only thing close is tootctl accounts --refresh all which just forces Mastodon to redownload everything, so I’d just end up with nearly 9GB of images all over again, albeit minus images from servers/accounts that don’t exist anymore.

Hope They Implement more efficient method

Me, too. I had some time today to look deeper into it and found out a way to manually delete stale accounts. This command can be used to get a listing of accounts which haven’t been seen in 3 months:

sudo -i -u postgres /bin/bash -l -c "psql -A -d mastodon -c \"SELECT username||'@'||domain FROM public.accounts WHERE last_webfingered_at < (CURRENT_TIMESTAMP - interval '3 months')\"" | tail -n +2 | head -n -1 > stale.txt

Then by whatever scripting means necessary the accounts can be deleted like so using Mastodon’s internal API:

su mastodon
cd ~/live
RAILS_ENV=production bundle exec rails r '
begin
    a = Account.find_by(username: "username", domain: "domain")
    a.destroy
rescue => err
end'

This has the added benefit of also deleting the avatars and header images. There can be multiples. In my case 23,549 accounts have been removed and about 8.7GB of data, all cached images of BS that shouldn’t be cached anymore.

EDIT: Added try/catch to the ruby script because Mastodon’s internal API is a bit screwy as it throws exceptions sometimes when doing this. It appears to be trying to do something with the data in the database after it’s been deleted. It seems like a bug, but the data is deleted, and that’s all that’s wanted here.

1 Like