Commit 18175bd7 by Miguel Araujo Perez

Performance boost in BaseFinderStorage.find_storage

Avoid listing all files for every finder for finding a file. This is
actually a bottleneck when the directory hierarchy is nested or the
number of files served in DEBUG mode is big. Since this flow is done in
every request, it slows down page loading.

In production environments where templates are usually cached performance
doesn't get hit by this.
parent a0761d9a
......@@ -117,11 +117,12 @@ class BaseFinderStorage(PipelineStorage):
def find_storage(self, name):
for finder in self.finders.get_finders():
for path, storage in finder.list([]):
prefix = getattr(storage, 'prefix', None)
matched_path = self.match_location(name, path, prefix)
if matched_path:
return matched_path, storage
path = finder.find(name)
if path:
for storage_root, storage in finder.storages.items():
if path.startswith(storage_root):
return path, storage
raise ValueError("The file '%s' could not be found with %r." % (name, self))
def _open(self, name, mode="rb"):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment