Skip to content

Commit

Permalink
Merge pull request #243 from eatclub/original
Browse files Browse the repository at this point in the history
Cache the static url to file mapping to speed up builds
  • Loading branch information
ibarria0 committed Jul 12, 2016
2 parents 06bde58 + 5b9a3dd commit 7af055c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cactus/site.py
Expand Up @@ -235,6 +235,7 @@ def build(self):

# Reset the static content
self._static = None
self._static_resources_dict = None

#TODO: Facility to reset the site, and reload config.
#TODO: Currently, we can't build a site instance multiple times
Expand Down Expand Up @@ -301,6 +302,15 @@ def static(self):

return self._static

def static_resources_dict(self):
"""
Retrieve a dictionary mapping URL's to static files
"""
if self._static_resources_dict is None:
self._static_resources_dict = dict((resource.link_url, resource) for resource in self.static())

return self._static_resources_dict

def _get_resource(self, src_url, resources):

if is_external(src_url):
Expand All @@ -310,10 +320,8 @@ def _get_resource(self, src_url, resources):
if split_char in src_url:
src_url = src_url.split(split_char)[0]

resources_dict = dict((resource.link_url, resource) for resource in resources)

if src_url in resources_dict:
return resources_dict[src_url].final_url
if src_url in resources:
return resources[src_url].final_url

return None

Expand All @@ -322,10 +330,10 @@ def _get_url(self, src_url, resources):
return self._get_resource(src_url, resources)

def get_url_for_static(self, src_path):
return self._get_url(src_path, self.static())
return self._get_url(src_path, self.static_resources_dict())

def get_url_for_page(self, src_path):
return self._get_url(src_path, self.pages())
return self._get_url(src_path, dict((resource.link_url, resource) for resource in self.pages()))

def buildStatic(self):
"""
Expand Down

0 comments on commit 7af055c

Please sign in to comment.