Jannis Leidel committed 185e7b8

Updated S3Storage backend to also respect the new AWS_PRELOAD_METADATA settings.

Comments (0)

Files changed (2)


 SECURE_URLS         = getattr(settings, 'AWS_S3_SECURE_URLS', False)
 BUCKET_PREFIX       = getattr(settings, 'AWS_BUCKET_PREFIX', '')
 CALLING_FORMAT      = getattr(settings, 'AWS_CALLING_FORMAT', CallingFormat.PATH)
+PRELOAD_METADATA    = getattr(settings, 'AWS_PRELOAD_METADATA', False)
 IS_GZIPPED          = getattr(settings, 'AWS_IS_GZIPPED', False)
 GZIP_CONTENT_TYPES  = getattr(settings, 'GZIP_CONTENT_TYPES', (
 class S3Storage(Storage):
     """Amazon Simple Storage Service"""
-    preload = False
     def __init__(self, bucket=settings.AWS_STORAGE_BUCKET_NAME,
             access_key=None, secret_key=None, acl=DEFAULT_ACL,
             calling_format=CALLING_FORMAT, encrypt=False,
-            gzip=IS_GZIPPED, gzip_content_types=GZIP_CONTENT_TYPES):
+            gzip=IS_GZIPPED, gzip_content_types=GZIP_CONTENT_TYPES,
+            preload_metadata=PRELOAD_METADATA):
         self.bucket = bucket
         self.acl = acl
         self.encrypt = encrypt
         self.gzip = gzip
         self.gzip_content_types = gzip_content_types
+        self.preload_metadata = preload_metadata
         if encrypt:
         self.headers = HEADERS
-        self.entries = self.preload and self._preload_entries() or {}
+        self._entries = {}
     def _get_access_keys(self):
         access_key = ACCESS_KEY_NAME
         return None, None
-    def _preload_entries(self):
-        entries = self.connection.list_bucket(self.bucket).entries
-        return dict((entry.key, entry) for entry in entries)
+    @property
+    def entries(self):
+        if self.preload_metadata and not self._entries:
+            self._entries = dict((entry.key, entry)
+                                for entry in self.connection.list_bucket(self.bucket).entries)
+        return self._entries
     def _get_connection(self):
         return AWSAuthConnection(*self._get_access_keys())
 class PreloadingS3Storage(S3Storage):
-    """
-    Preloading Amazon Simple Storage Service
-    This preloads info about the bucket entries to allow faster use with
-    staticfiles's collectstatic.
-    """
-    preload = True
+    pass
 class S3StorageFile(File):
     def __init__(self, name, storage, mode):


         if self.preload_metadata and not self._entries:
             self._entries = dict((self._decode_name(entry.key), entry)
                                 for entry in self.bucket.list())
-            print self._entries
         return self._entries
     def _get_access_keys(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.