Mercurial > piecrust2
changeset 905:1d0364614665
internal: Sources can cache their pages in addition to their items.
Added `getAllPages` to content sources to prevent having to look up cached
page objects in the page repository all the time.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 23 Jul 2017 08:26:57 -0700 |
parents | cc2647360036 |
children | 1c6a4d2ec16e |
files | piecrust/dataproviders/blog.py piecrust/dataproviders/pageiterator.py piecrust/sources/base.py piecrust/sources/blogarchives.py |
diffstat | 4 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/dataproviders/blog.py Sun Jul 23 08:25:45 2017 -0700 +++ b/piecrust/dataproviders/blog.py Sun Jul 23 08:26:57 2017 -0700 @@ -87,12 +87,10 @@ taxonomies.append(Taxonomy(tn, tax_cfg)) tax_index[tn] = {} - app = self._app page = self._page source = self._sources[0] - for item in source.getAllContents(): - post = app.getPage(source, item) + for post in source.getAllPages(): post_dt = post.datetime year = post_dt.year
--- a/piecrust/dataproviders/pageiterator.py Sun Jul 23 08:25:45 2017 -0700 +++ b/piecrust/dataproviders/pageiterator.py Sun Jul 23 08:26:57 2017 -0700 @@ -362,9 +362,7 @@ def __iter__(self): source = self.source - app = source.app - for item in source.getAllContents(): - yield app.getPage(source, item) + yield from source.getAllPages() class PaginationDataBuilderIterator:
--- a/piecrust/sources/base.py Sun Jul 23 08:25:45 2017 -0700 +++ b/piecrust/sources/base.py Sun Jul 23 08:26:57 2017 -0700 @@ -84,6 +84,7 @@ self.name = name self.config = config or {} self._cache = None + self._page_cache = None @property def is_theme_source(self): @@ -99,6 +100,14 @@ def getItemMtime(self, item): raise NotImplementedError() + def getAllPages(self): + if self._page_cache is not None: + return self._page_cache + + getter = self.app.getPage + self._page_cache = [getter(self, i) for i in self.getAllContents()] + return self._page_cache + def getAllContents(self): if self._cache is not None: return self._cache
--- a/piecrust/sources/blogarchives.py Sun Jul 23 08:25:45 2017 -0700 +++ b/piecrust/sources/blogarchives.py Sun Jul 23 08:26:57 2017 -0700 @@ -108,11 +108,7 @@ return month_index = {} - src = self._inner_source - app = src.app - for item in self._inner_source.getAllContents(): - page = app.getPage(src, item) - + for page in self._inner_source.getAllPages(): if page.datetime.year != self._year: continue