filegostorage

File Cleanup Bottleneck


As the number of users grew, there was a problem with deleting uploaded files. I use tus.io when uploading a file. If a file has been in the file system for a certain amount of time, and it was not successfully uploaded (upload was interrupted, or something else happened and the file upload was not successful) the file will be deleted. Currently all file information is in sync.Map - this is an old solution that I want to abandon. It works like this: Opens the specified directory with os.Open. Reads the contents of the directory with Readdir(-1), getting information about the files. Iterates over each file in the directory. And deletion if necessary.

So I am looking for options much simpler than the current one, for example, to create a simple in memory storage, where the file will be stored, the background task will track which entries have a TTL stack and will cause deletion, directly without searching the entire directory. But maybe there is something even simpler and more optimal?


Solution

  • From the earlier comment

    I think storing files in memory will make it worse, Instead why not store all uploaded files in a single directory dir1 and once upload is successful and valid then move those files to another directory. Let a daily CRON job delete files inside of dir1 that has created time > 2 days or something similar.