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 Aug 14, 2023
1 parent b5f4d95 commit 6e8e918
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import platform
import re
from functools import lru_cache
from urllib.error import URLError
from urllib.parse import quote, quote_plus, urlsplit, urlunsplit
from urllib.request import urlopen, Request
Expand All @@ -19,6 +20,11 @@
url_pat = re.compile(r'^(https?|ftp):\/\/')


@lru_cache
def get_or_create_storage(storage):
return get_module_class(storage)()


def serialize_image_file(image_file):
if image_file.size is None:
raise ThumbnailError('Trying to serialize an ``ImageFile`` with a '
Expand All @@ -33,12 +39,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 6e8e918

Please sign in to comment.