Permalink
Browse files

Don't instantiate the local compressor storage backend all the time.

  • Loading branch information...
1 parent c2f414d commit 600361925291dc4c96a691fbd79df0f99ef3543c @jezdez jezdez committed Nov 2, 2011
Showing with 7 additions and 4 deletions.
  1. +2 −3 compressor/base.py
  2. +5 −1 compressor/storage.py
View
5 compressor/base.py
@@ -13,7 +13,7 @@
from compressor.conf import settings
from compressor.exceptions import CompressorError, UncompressableFileError
from compressor.filters import CompilerFilter
-from compressor.storage import default_storage
+from compressor.storage import default_storage, compressor_file_storage
from compressor.signals import post_compress
from compressor.utils import get_class, staticfiles
from compressor.utils.decorators import cached_property, memoize
@@ -74,8 +74,7 @@ def get_filename(self, basename):
filename = self.storage.path(basename)
except NotImplementedError:
# remote storages don't implement path, access the file locally
- local_storage = get_storage_class('compressor.storage.CompressorFileStorage')()
- filename = local_storage.path(basename)
+ filename = compressor_file_storage.path(basename)
# secondly try finding the file in the root
elif self.finders:
filename = self.finders.find(basename)
View
6 compressor/storage.py
@@ -3,7 +3,7 @@
from datetime import datetime
from django.core.files.storage import FileSystemStorage, get_storage_class
-from django.utils.functional import LazyObject
+from django.utils.functional import LazyObject, SimpleLazyObject
from compressor.conf import settings
@@ -42,6 +42,10 @@ def get_available_name(self, name):
return name
+compressor_file_storage = SimpleLazyObject(
+ lambda: get_storage_class('compressor.storage.CompressorFileStorage')())
+
+
class GzipCompressorFileStorage(CompressorFileStorage):
"""
The standard compressor file system storage that gzips storage files

0 comments on commit 6003619

Please sign in to comment.