Mercurial > piecrust2
diff piecrust/page.py @ 96:0445a2232de7
Improvements and fixes to incremental baking.
* Better handling of the render pass during page rendering.
* Used sources are paired with the pass they were used in.
* Proper use and invalidation of the rendered segments cache based on render
passes.
* The `Assetor` is also better tracking what was used in a page.
* Add flags on a page to get better caching information for the debug window.
* Property invalidation of the previous bake record when needed.
* Better information about why pages are delayed.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 07 Sep 2014 23:48:57 -0700 |
parents | e293f08d954e |
children | b6ec402d32bb |
line wrap: on
line diff
--- a/piecrust/page.py Sun Sep 07 21:37:10 2014 -0700 +++ b/piecrust/page.py Sun Sep 07 23:48:57 2014 -0700 @@ -11,7 +11,6 @@ from werkzeug.utils import cached_property from piecrust.configuration import (Configuration, ConfigurationError, parse_config_header) -from piecrust.environment import PHASE_PAGE_PARSING logger = logging.getLogger(__name__) @@ -33,6 +32,10 @@ return values +FLAG_NONE = 0 +FLAG_RAW_CACHE_VALID = 2**0 + + class Page(object): def __init__(self, source, source_metadata, rel_path): self.source = source @@ -40,6 +43,7 @@ self.rel_path = rel_path self._config = None self._raw_content = None + self._flags = FLAG_NONE self._datetime = None @property @@ -59,6 +63,10 @@ return os.path.getmtime(self.path) @property + def flags(self): + return self._flags + + @property def config(self): self._load() return self._config @@ -123,14 +131,12 @@ if self._config is not None: return - eis = self.app.env.exec_info_stack - eis.pushPage(self, PHASE_PAGE_PARSING, None) - try: - config, content = load_page(self.app, self.path, self.path_mtime) - self._config = config - self._raw_content = content - finally: - eis.popPage() + config, content, was_cache_valid = load_page(self.app, self.path, + self.path_mtime) + self._config = config + self._raw_content = content + if was_cache_valid: + self._flags |= FLAG_RAW_CACHE_VALID class PageLoadingError(Exception): @@ -195,26 +201,19 @@ def _do_load_page(app, path, path_mtime): - exec_info = app.env.exec_info_stack.current_page_info - if exec_info is None: - raise Exception("Loading page '%s' but not execution context has " - "been created for it." % path) - # Check the cache first. cache = app.cache.getCache('pages') cache_path = "%s.json" % hashlib.md5(path.encode('utf8')).hexdigest() page_time = path_mtime or os.path.getmtime(path) if cache.isValid(cache_path, page_time): - exec_info.was_cache_valid = True cache_data = json.loads(cache.read(cache_path), object_pairs_hook=collections.OrderedDict) config = PageConfiguration(values=cache_data['config'], validate=False) content = json_load_segments(cache_data['content']) - return config, content + return config, content, True # Nope, load the page from the source file. - exec_info.was_cache_valid = False logger.debug("Loading page configuration from: %s" % path) with codecs.open(path, 'r', 'utf-8') as fp: raw = fp.read() @@ -235,7 +234,7 @@ 'content': json_save_segments(content)} cache.write(cache_path, json.dumps(cache_data)) - return config, content + return config, content, False segment_pattern = re.compile(