Mercurial > piecrust2
comparison piecrust/sources/blogarchives.py @ 989:8adc27285d93
bake: Big pass on bake performance.
- Reduce the amount of data passed between processes.
- Make inter-process data simple objects to make it easier to test with
alternatives to pickle.
- Make sources have the basic requirement to be able to find a content item
from an item spec (path).
- Make Hoedown the default Markdown formatter.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 19 Nov 2017 14:29:17 -0800 |
parents | 1d0364614665 |
children | ba809c221a27 |
comparison
equal
deleted
inserted
replaced
988:f83ae0a5d793 | 989:8adc27285d93 |
---|---|
5 from piecrust.data.filters import PaginationFilter, IFilterClause | 5 from piecrust.data.filters import PaginationFilter, IFilterClause |
6 from piecrust.dataproviders.pageiterator import ( | 6 from piecrust.dataproviders.pageiterator import ( |
7 PageIterator, HardCodedFilterIterator, DateSortIterator) | 7 PageIterator, HardCodedFilterIterator, DateSortIterator) |
8 from piecrust.page import Page | 8 from piecrust.page import Page |
9 from piecrust.pipelines._pagebaker import PageBaker | 9 from piecrust.pipelines._pagebaker import PageBaker |
10 from piecrust.pipelines._pagerecords import PagePipelineRecordEntry | 10 from piecrust.pipelines._pagerecords import ( |
11 PagePipelineRecordEntry, | |
12 add_page_job_result, merge_job_result_into_record_entry) | |
11 from piecrust.pipelines.base import ( | 13 from piecrust.pipelines.base import ( |
12 ContentPipeline, get_record_name_for_source) | 14 ContentPipeline, |
15 create_job, get_record_name_for_source, content_item_from_job) | |
13 from piecrust.routing import RouteParameter | 16 from piecrust.routing import RouteParameter |
14 from piecrust.sources.base import ContentItem | 17 from piecrust.sources.base import ContentItem |
15 from piecrust.sources.generator import GeneratorSourceBase | 18 from piecrust.sources.generator import GeneratorSourceBase |
16 from piecrust.sources.list import ListSource | 19 from piecrust.sources.list import ListSource |
17 | 20 |
36 self._raw_item = _year_index % {'template': tpl_name} | 39 self._raw_item = _year_index % {'template': tpl_name} |
37 | 40 |
38 def getSupportedRouteParameters(self): | 41 def getSupportedRouteParameters(self): |
39 return [RouteParameter('year', RouteParameter.TYPE_INT4)] | 42 return [RouteParameter('year', RouteParameter.TYPE_INT4)] |
40 | 43 |
41 def findContent(self, route_params): | 44 def findContentFromRoute(self, route_params): |
42 year = route_params['year'] | 45 year = route_params['year'] |
43 spec = '_index' | 46 return ContentItem( |
44 metadata = { | 47 '_index', |
45 'record_entry_spec': '_index[%04d]' % year, | 48 {'route_params': {'year': year}}) |
46 'route_params': {'year': year} | |
47 } | |
48 return ContentItem(spec, metadata) | |
49 | 49 |
50 def prepareRenderContext(self, ctx): | 50 def prepareRenderContext(self, ctx): |
51 ctx.pagination_source = self.inner_source | 51 ctx.pagination_source = self.inner_source |
52 | 52 |
53 route_params = ctx.page.source_metadata['route_params'] | 53 route_params = ctx.page.source_metadata['route_params'] |
176 self._buildDirtyYears(ctx) | 176 self._buildDirtyYears(ctx) |
177 logger.debug("Got %d dirty years out of %d." % | 177 logger.debug("Got %d dirty years out of %d." % |
178 (len(self._dirty_years), len(self._all_years))) | 178 (len(self._dirty_years), len(self._all_years))) |
179 | 179 |
180 jobs = [] | 180 jobs = [] |
181 rec_fac = self.createRecordEntry | |
182 current_record = ctx.current_record | |
183 | |
181 for y in self._dirty_years: | 184 for y in self._dirty_years: |
182 item = ContentItem( | 185 record_entry_spec = '_index[%04d]' % y |
183 '_index', | 186 |
184 { | 187 jobs.append(create_job(self, '_index', |
185 'record_entry_spec': '_index[%04d]' % y, | 188 year=y, |
186 'route_params': {'year': y} | 189 record_entry_spec=record_entry_spec)) |
187 }) | 190 |
188 jobs.append(self.createJob(item)) | 191 entry = rec_fac(record_entry_spec) |
192 current_record.addEntry(entry) | |
193 | |
189 if len(jobs) > 0: | 194 if len(jobs) > 0: |
190 return jobs | 195 return jobs |
191 return None | 196 return None |
192 | 197 |
193 def run(self, job, ctx, result): | 198 def run(self, job, ctx, result): |
194 page = Page(self.source, job.content_item) | 199 year = job['year'] |
200 content_item = ContentItem('_index', | |
201 {'year': year, | |
202 'route_params': {'year': year}}) | |
203 page = Page(self.source, content_item) | |
204 | |
195 prev_entry = ctx.previous_entry | 205 prev_entry = ctx.previous_entry |
196 cur_entry = result.record_entry | 206 rdr_subs = self._pagebaker.bake(page, prev_entry) |
197 cur_entry.year = job.content_item.metadata['route_params']['year'] | 207 |
198 self._pagebaker.bake(page, prev_entry, cur_entry) | 208 add_page_job_result(result) |
209 result['subs'] = rdr_subs | |
210 result['year'] = page.source_metadata['year'] | |
211 | |
212 def handleJobResult(self, result, ctx): | |
213 existing = ctx.record_entry | |
214 merge_job_result_into_record_entry(existing, result) | |
215 existing.year = result['year'] | |
199 | 216 |
200 def postJobRun(self, ctx): | 217 def postJobRun(self, ctx): |
201 # Create bake entries for the years that were *not* dirty. | 218 # Create bake entries for the years that were *not* dirty. |
202 # Otherwise, when checking for deleted pages, we would not find any | 219 # Otherwise, when checking for deleted pages, we would not find any |
203 # outputs and would delete those files. | 220 # outputs and would delete those files. |