Rails & Dragonfly: Cleaning up unused images
-
27-09-2019 - |
Question
I'm working on cleaning up an old Rails 2.3.5 app that uses Dragonfly to store its images.
I have a feeling there are far more images in the filestore than records in the database, but due to Dragonfly's less than transparent naming scheme I have no idea how to find out which files in the filestore belong to actual records.
Anyone have a good idea how I can clean this up? I'd love to get rid of several gigabytes of unused data.
Solution
You could look up the media records in your database where you should find a column postfixed with "_uid". This column contains the relative path to your media files in your media folder. You could then remove the files that cannot be found in your database. Be careful: as I can see there is one additional file postfixed ".extra" per media file that you should keep (but I don't know what it is for).
I am thinking about implementing such a functionality with a "Cleanup media data store" Button in my admin interface. I didn't try this out yet, though.