Skip to content

Commit

Permalink
Fix slow performance with S3 jazzband#662 jazzband#301 jazzband#508
Browse files Browse the repository at this point in the history
  • Loading branch information
krukas committed Jan 24, 2023
1 parent b5f4d95 commit 202c040
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@

url_pat = re.compile(r'^(https?|ftp):\/\/')

STORAGES_CACHE = {}


def get_or_create_storage(storage):
if storage not in STORAGES_CACHE:
STORAGES_CACHE[storage] = get_module_class(storage)()
return STORAGES_CACHE[storage]


def serialize_image_file(image_file):
if image_file.size is None:
Expand All @@ -33,12 +41,7 @@ def serialize_image_file(image_file):

def deserialize_image_file(s):
data = deserialize(s)

class LazyStorage(LazyObject):
def _setup(self):
self._wrapped = get_module_class(data['storage'])()

image_file = ImageFile(data['name'], LazyStorage())
image_file = ImageFile(data['name'], get_or_create_storage(data['storage']))
image_file.set_size(data['size'])
return image_file

Expand Down

0 comments on commit 202c040

Please sign in to comment.