uploads: fix temp files not being cleaned up quickly enough.

Fix temp files generated during the upload process not being cleaned up quickly enough. This included
downloaded files, generated preview images, and Ugoira video conversions.

Before we relied on `Tempfile` cleaning up files automatically. But this only happened when the
Tempfile object was garbage collected, which could take a long time. In the meantime we could have
hundreds of megabytes of temp files hanging around.

The fix is to explicitly close temp files when we're done with them. But the standard `Tempfile`
class doesn't immediately delete the file when it's closed. So we also have to introduce a
Danbooru::Tempfile wrapper that deletes the tempfile as soon as it's closed.
This commit is contained in:
evazion
2022-11-15 17:34:59 -06:00
parent 21a779455f
commit e935f01358
14 changed files with 67 additions and 27 deletions

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class StorageManagerTest < ActiveSupport::TestCase
def tempfile(data)
file = Tempfile.new
file = Danbooru::Tempfile.new
file.write(data)
file.flush
file