Documents with Image and File fields don't clean up orphaned files when they are removed #162

Open
JedWatson opened this Issue Feb 6, 2014 · 4 comments

6 participants

@JedWatson
KeystoneJS member

As mentioned by @alanshaw in #161.

One solution would be to create a 'cleanup' method on Documents that gets the files and images referenced in any LocalFile, S3File, CloudinaryImage (etc) fields and deletes them.

It could potentially check for references to the same files in the same field in other documents in the collection first to make sure it didn't incorrectly remove files in use by other documents (e.g. because of duplication or copy/paste) - this may cause poor performance on unindexed fields in larger collections though.

We could also prompt in the Admin UI when Items are deleted to run the cleanup method (if the List has file fields in it), so the user has the choice.

Don't want to be too aggressive about automatically cleaning up but it would be good to have the option for Keystone to clean up after itself over time.

@jdarling

I like the prompt the admin user approach. Seems like it would be the easiest to implement in the near future. Reference checks tend to get messy and are difficult to get right.

@jamlen

+1 for the UI Prompt

@alanshaw

I can't attach a schema post remove hook to cover this use case because Automattic/mongoose#1241

So this is really needed.

@Yinear

The remove file button is not functional also.

How can I force the file to be removed ?
Like this?
XXX.schema.post('delete', function(next) {
//do some force remove
});

@mxstbr mxstbr added bug and removed new feature discussion labels Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment