comparison piecrust/data/provider.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 923699e816d0
children f130365568ff
comparison
equal deleted inserted replaced
113:de257cc40ce1 114:371a6c879ab9
115 def _buildYearlyArchive(self): 115 def _buildYearlyArchive(self):
116 if self._yearly is not None: 116 if self._yearly is not None:
117 return self._yearly 117 return self._yearly
118 118
119 self._yearly = [] 119 self._yearly = []
120 for fac in self._source.getPageFactories(): 120 for post in self._source.getPages():
121 post = fac.buildPage()
122 year = post.datetime.strftime('%Y') 121 year = post.datetime.strftime('%Y')
123 122
124 posts_this_year = next( 123 posts_this_year = next(
125 filter(lambda y: y.name == year, self._yearly), 124 filter(lambda y: y.name == year, self._yearly),
126 None) 125 None)
140 def _buildMonthlyArchive(self): 139 def _buildMonthlyArchive(self):
141 if self._monthly is not None: 140 if self._monthly is not None:
142 return self._monthly 141 return self._monthly
143 142
144 self._monthly = [] 143 self._monthly = []
145 for fac in self._source.getPageFactories(): 144 for post in self._source.getPages():
146 post = fac.buildPage()
147 month = post.datetime.strftime('%B %Y') 145 month = post.datetime.strftime('%B %Y')
148 146
149 posts_this_month = next( 147 posts_this_month = next(
150 filter(lambda m: m.name == month, self._monthly), 148 filter(lambda m: m.name == month, self._monthly),
151 None) 149 None)
166 def _buildTaxonomy(self, tax_name): 164 def _buildTaxonomy(self, tax_name):
167 if tax_name in self._taxonomies: 165 if tax_name in self._taxonomies:
168 return self._taxonomies[tax_name] 166 return self._taxonomies[tax_name]
169 167
170 posts_by_tax_value = {} 168 posts_by_tax_value = {}
171 for fac in self._source.getPageFactories(): 169 for post in self._source.getPages():
172 post = fac.buildPage()
173 tax_values = post.config.get(tax_name) 170 tax_values = post.config.get(tax_name)
174 if tax_values is None: 171 if tax_values is None:
175 continue 172 continue
176 if not isinstance(tax_values, list): 173 if not isinstance(tax_values, list):
177 tax_values = [tax_values] 174 tax_values = [tax_values]