keichan34 / exfile

File upload persistence and processing for Phoenix / Plug
MIT License
90 stars 19 forks source link

Autoremoving files if they models has been removed #46

Open asiniy opened 8 years ago

asiniy commented 8 years ago

It's pretty simple thing, but I think it should be implemented later. The problem is (as I understood it from the code and current behaviour) that if we remove record from the database there is no automatic purging for its stored files (no matter when they are stored - in the b2, local-machine and so on).

This mechanism have to be implemented. WDYT?

keichan34 commented 8 years ago

It's a bit hacky, but I currently implement this by checking every week or so to find files that have been deleted in the database, then a vacuum task will go through the backend and remove them if they aren't referenced anymore. It isn't ideal, but it works for me at a small scale.

It does need to be implemented at some point in the future, though.

asiniy commented 8 years ago

@keichan34 yeah, unfortunately you can't implement it without hack. Like:

Repo.get(Model, id)
|> Repo.delete
|> Exfile.VacuumFile # do it asynchroyously, of course