From 48e20b0c740d4a4d8878deae1c32115db7b539bd Mon Sep 17 00:00:00 2001 From: Niran Babalola Date: Thu, 26 Jan 2012 07:25:54 -0600 Subject: [PATCH] Avoid network I/O for remote storages in get_filename --- compressor/base.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compressor/base.py b/compressor/base.py index a1ee033..0fa6d4f 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -74,14 +74,18 @@ class Compressor(object): 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