Clean up files that were uploaded with the upload API
Description
We have been replacing old code that handles picture upload with the new upload API (!818 (merged), see #45 (closed) for the current state). The uploaded files and the entries in the uploads
table are, however, never deleted.
There are two problems:
- Tables don't contain the file name anymore, but the UUID of the upload. For example, the column
photo
infs_foodsaver
used to contain the filename. The nightly maintenance could then delete all files that were not listed in that column. Now, the column contains the UUID (at least for all files that were uploaded after %Release 'Birne': August 2020🍐 ) which needs to be cross-checked withuploads
, which contains the UUID and the filename. - All pictures files from across the website (profile photos, baskets, header photos of working groups, ...) are being saved in the same directory. The
uploads
table does not contain information about how a picture is being used. In order to check if a file is still in use, we need to cross-checkuploads.uuid
withfs_foodsaver.photo
,fs_fairteiler.picture
,fs_blog_entry.picture
, and in the future alsofs_basket.picture
,fs_wallpost.attach
,fs_bezirk.photo
.
Goal
Clean up the uploads
table and remove unused files.
Solution
-
Mark all uploads with a usage type and id -
header images of food share points -
profile pictures ( !3121 (merged)) -
blog pictures -
header images of working groups -
baskets -
wall posts
-
- Delete old files when a new one is set
-
header images of food share points -
profile pictures ( !3121 (merged)) -
blog pictures -
header images of working groups -
baskets -
wall posts (can attached pictures be changed?)
-
- Delete files whose usage id is not valid anymore in the maintenance script
- How to handle old files? Checking all tables / usage types might be slow. Only update a few per night?
Links / references
Edited by Alex