Mercurial > piecrust2
comparison piecrust/pipelines/_pagerecords.py @ 1136:5f97b5b59dfe
bake: Optimize cache handling for the baking process.
- Get rid of the 2-level pipeline runs... handle a single set of passes.
- Go back to load/render segments/layout passes for pages.
- Add descriptions of what each job batch does.
- Improve the taxonomy pipeline so it doesn't re-bake terms that don't need
to be re-baked.
- Simplify some of the code.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 23 Apr 2018 21:47:49 -0700 |
parents | 298b07a899b5 |
children |
comparison
equal
deleted
inserted
replaced
1135:6350ee084273 | 1136:5f97b5b59dfe |
---|---|
1 import copy | |
2 from piecrust.pipelines.records import RecordEntry, get_flag_descriptions | 1 from piecrust.pipelines.records import RecordEntry, get_flag_descriptions |
3 | 2 |
4 | 3 |
5 class SubPageFlags: | 4 class SubPageFlags: |
6 FLAG_NONE = 0 | 5 FLAG_NONE = 0 |
7 FLAG_BAKED = 2**0 | 6 FLAG_BAKED = 2**0 |
8 FLAG_FORCED_BY_SOURCE = 2**1 | 7 FLAG_FORCED_BY_SOURCE = 2**1 |
9 FLAG_FORCED_BY_NO_PREVIOUS = 2**2 | 8 FLAG_FORCED_BY_NO_PREVIOUS = 2**2 |
10 FLAG_FORCED_BY_PREVIOUS_ERRORS = 2**3 | 9 FLAG_FORCED_BY_NO_RECORD = 2**3 |
11 FLAG_FORCED_BY_GENERAL_FORCE = 2**4 | 10 FLAG_FORCED_BY_PREVIOUS_ERRORS = 2**4 |
12 FLAG_RENDER_CACHE_INVALIDATED = 2**5 | 11 FLAG_FORCED_BY_GENERAL_FORCE = 2**5 |
13 FLAG_COLLAPSED_FROM_LAST_RUN = 2**6 | 12 FLAG_RENDER_CACHE_INVALIDATED = 2**6 |
13 FLAG_COLLAPSED_FROM_LAST_RUN = 2**7 | |
14 | 14 |
15 | 15 |
16 def create_subpage_job_result(out_uri, out_path): | 16 def create_subpage_job_result(out_uri, out_path): |
17 return { | 17 return { |
18 'out_uri': out_uri, | 18 'out_uri': out_uri, |
21 'errors': [], | 21 'errors': [], |
22 'render_info': None | 22 'render_info': None |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 def was_subpage_clean(sub): | |
27 return ((sub['flags'] & SubPageFlags.FLAG_BAKED) == 0 and | |
28 len(sub['errors']) == 0) | |
29 | |
30 | |
31 def was_subpage_baked(sub): | |
32 return (sub['flags'] & SubPageFlags.FLAG_BAKED) != 0 | |
33 | |
34 | |
35 def was_subpage_baked_successfully(sub): | |
36 return was_subpage_baked(sub) and len(sub['errors']) == 0 | |
37 | |
38 | |
39 class PagePipelineRecordEntry(RecordEntry): | 26 class PagePipelineRecordEntry(RecordEntry): |
40 FLAG_NONE = 0 | 27 FLAG_NONE = 0 |
41 FLAG_NEW = 2**0 | 28 FLAG_SOURCE_MODIFIED = 2**0 |
42 FLAG_SOURCE_MODIFIED = 2**1 | 29 FLAG_SEGMENTS_RENDERED = 2**1 |
43 FLAG_OVERRIDEN = 2**2 | 30 FLAG_OVERRIDEN = 2**2 |
44 FLAG_COLLAPSED_FROM_LAST_RUN = 2**3 | 31 FLAG_COLLAPSED_FROM_LAST_RUN = 2**3 |
45 FLAG_IS_DRAFT = 2**4 | 32 FLAG_IS_DRAFT = 2**4 |
46 FLAG_ABORTED_FOR_SOURCE_USE = 2**5 | 33 FLAG_ABORTED_FOR_SOURCE_USE = 2**5 |
47 | 34 |
52 self.route_params = None | 39 self.route_params = None |
53 self.timestamp = None | 40 self.timestamp = None |
54 self.subs = [] | 41 self.subs = [] |
55 | 42 |
56 @property | 43 @property |
57 def was_touched(self): | |
58 return (self.flags & self.FLAG_SOURCE_MODIFIED) != 0 | |
59 | |
60 @property | |
61 def was_overriden(self): | |
62 return (self.flags & self.FLAG_OVERRIDEN) != 0 | |
63 | |
64 @property | |
65 def num_subs(self): | 44 def num_subs(self): |
66 return len(self.subs) | 45 return len(self.subs) |
67 | |
68 @property | |
69 def was_any_sub_baked(self): | |
70 for o in self.subs: | |
71 if was_subpage_baked(o): | |
72 return True | |
73 return False | |
74 | 46 |
75 @property | 47 @property |
76 def has_any_error(self): | 48 def has_any_error(self): |
77 if len(self.errors) > 0: | 49 if len(self.errors) > 0: |
78 return True | 50 return True |
79 for o in self.subs: | 51 for o in self.subs: |
80 if len(o['errors']) > 0: | 52 if len(o['errors']) > 0: |
81 return True | 53 return True |
82 return False | 54 return False |
55 | |
56 def hasFlag(self, flag): | |
57 return (self.flags & flag) != 0 | |
83 | 58 |
84 def getSub(self, page_num): | 59 def getSub(self, page_num): |
85 return self.subs[page_num - 1] | 60 return self.subs[page_num - 1] |
86 | 61 |
87 def getAllErrors(self): | 62 def getAllErrors(self): |
116 'RenderInfo': _describe_render_info(sub['render_info']) | 91 'RenderInfo': _describe_render_info(sub['render_info']) |
117 } | 92 } |
118 return d | 93 return d |
119 | 94 |
120 | 95 |
121 def add_page_job_result(result): | |
122 result.update({ | |
123 'flags': PagePipelineRecordEntry.FLAG_NONE, | |
124 'errors': [], | |
125 'subs': [] | |
126 }) | |
127 | |
128 | |
129 def merge_job_result_into_record_entry(record_entry, result): | |
130 record_entry.flags |= result['flags'] | |
131 record_entry.errors += result['errors'] | |
132 record_entry.subs += result['subs'] | |
133 | |
134 | |
135 flag_descriptions = { | 96 flag_descriptions = { |
136 PagePipelineRecordEntry.FLAG_NEW: 'new', | |
137 PagePipelineRecordEntry.FLAG_SOURCE_MODIFIED: 'touched', | 97 PagePipelineRecordEntry.FLAG_SOURCE_MODIFIED: 'touched', |
98 PagePipelineRecordEntry.FLAG_SEGMENTS_RENDERED: 'rendered segments', | |
138 PagePipelineRecordEntry.FLAG_OVERRIDEN: 'overriden', | 99 PagePipelineRecordEntry.FLAG_OVERRIDEN: 'overriden', |
139 PagePipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run', | 100 PagePipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run', |
140 PagePipelineRecordEntry.FLAG_IS_DRAFT: 'draft', | 101 PagePipelineRecordEntry.FLAG_IS_DRAFT: 'draft', |
141 PagePipelineRecordEntry.FLAG_ABORTED_FOR_SOURCE_USE: 'aborted for source use'} | 102 PagePipelineRecordEntry.FLAG_ABORTED_FOR_SOURCE_USE: ('aborted for ' |
103 'source use')} | |
142 | 104 |
143 | 105 |
144 sub_flag_descriptions = { | 106 sub_flag_descriptions = { |
145 SubPageFlags.FLAG_BAKED: 'baked', | 107 SubPageFlags.FLAG_BAKED: 'baked', |
146 SubPageFlags.FLAG_FORCED_BY_SOURCE: 'forced by source', | 108 SubPageFlags.FLAG_FORCED_BY_SOURCE: 'forced by source', |
147 SubPageFlags.FLAG_FORCED_BY_NO_PREVIOUS: 'forced b/c new', | 109 SubPageFlags.FLAG_FORCED_BY_NO_PREVIOUS: 'forced b/c new', |
110 SubPageFlags.FLAG_FORCED_BY_NO_RECORD: 'forced b/c no record', | |
148 SubPageFlags.FLAG_FORCED_BY_PREVIOUS_ERRORS: 'forced by errors', | 111 SubPageFlags.FLAG_FORCED_BY_PREVIOUS_ERRORS: 'forced by errors', |
149 SubPageFlags.FLAG_FORCED_BY_GENERAL_FORCE: 'manually forced', | 112 SubPageFlags.FLAG_FORCED_BY_GENERAL_FORCE: 'manually forced', |
150 SubPageFlags.FLAG_RENDER_CACHE_INVALIDATED: 'cache invalidated', | 113 SubPageFlags.FLAG_RENDER_CACHE_INVALIDATED: 'cache invalidated', |
151 SubPageFlags.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run' | 114 SubPageFlags.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run' |
152 } | 115 } |