Mercurial > piecrust2
diff piecrust/sources/base.py @ 114:371a6c879ab9
When possible, try and batch-load pages so we only lock once.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 19 Oct 2014 00:33:28 -0700 |
parents | b3ce11b2cf36 |
children | 8d16ca75075f |
line wrap: on
line diff
--- a/piecrust/sources/base.py Sun Oct 19 00:30:44 2014 -0700 +++ b/piecrust/sources/base.py Sun Oct 19 00:33:28 2014 -0700 @@ -26,6 +26,12 @@ page_ref_pattern = re.compile(r'(?P<src>[\w]+)\:(?P<path>.*?)(;|$)') +def build_pages(app, factories): + with app.env.page_repository.startBatchGet(): + for f in factories: + yield f.buildPage() + + class PageNotFoundError(Exception): pass @@ -207,6 +213,9 @@ return self.app.theme_dir return self.app.root_dir + def getPages(self): + return build_pages(self.app, self.getPageFactories()) + def getPageFactories(self): if self._factories is None: self._factories = list(self.buildPageFactories()) @@ -383,8 +392,7 @@ # iterator chain. It acts as the end. def __iter__(self): - for factory in self.source.getPageFactories(): - yield factory.buildPage() + return self.source.getPages() class DateSortIterator(object):