Browse files

Avoid network I/O for remote storages in get_filename

  • Loading branch information...
1 parent ab97095 commit 48e20b0c740d4a4d8878deae1c32115db7b539bd @niran niran committed Jan 26, 2012
Showing with 10 additions and 6 deletions.
  1. +10 −6 compressor/base.py
View
16 compressor/base.py
@@ -74,14 +74,18 @@ def get_filepath(self, content, basename=None):
def get_filename(self, basename):
filename = None
# first try finding the file in the root
- if self.storage.exists(basename):
- try:
- filename = self.storage.path(basename)
- except NotImplementedError:
- # remote storages don't implement path, access the file locally
+ try:
+ # call path first so remote storages don't make it to exists,
+ # which would cause network I/O
+ filename = self.storage.path(basename)
+ if not self.storage.exists(basename):
+ filename = None
+ except NotImplementedError:
+ # remote storages don't implement path, access the file locally
+ if compressor_file_storage.exists(basename):
filename = compressor_file_storage.path(basename)
# secondly try to find it with staticfiles (in debug mode)
- elif self.finders:
+ if not filename and self.finders:
filename = self.finders.find(urllib.url2pathname(basename))
if filename:
return filename

0 comments on commit 48e20b0

Please sign in to comment.