From ba0da1981001cb57e9381753ab1bff1a4992ad07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 5 Aug 2022 20:59:51 +0200 Subject: [PATCH] Rework file upload structure to use subfolders for better file performance --- shimatta_kenkyusho/shimatta_modules/RandomFileName.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shimatta_kenkyusho/shimatta_modules/RandomFileName.py b/shimatta_kenkyusho/shimatta_modules/RandomFileName.py index 279fe27..d457715 100644 --- a/shimatta_kenkyusho/shimatta_modules/RandomFileName.py +++ b/shimatta_kenkyusho/shimatta_modules/RandomFileName.py @@ -6,8 +6,13 @@ from django.utils.deconstruct import deconstructible @deconstructible class RandomFileName(object): def __init__(self, path): - self.path = os.path.join(path, "%s%s") + self.path = os.path.join(path, "%s/%s/%s%s") def __call__(self, _, filename): extension = os.path.splitext(filename)[1] - return self.path % (uuid.uuid4(), extension) \ No newline at end of file + file_uuid = uuid.uuid4() + uuid_str = str(file_uuid) + first_char = uuid_str[0] + second_char = uuid_str[1] + + return self.path % (first_char, second_char, file_uuid, extension)