Mercurial > piecrust2
comparison piecrust/dataproviders/blog.py @ 874:f4608e2e80ce
data: Optimize page data creation.
`datetime.strftime` was pretty costly so it's no lazily-computed in some
places, and replaced with some better alternative elsewhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 15 Jun 2017 07:31:50 -0700 |
parents | d231a10d18f9 |
children | 1d0364614665 |
comparison
equal
deleted
inserted
replaced
873:93ea115027fc | 874:f4608e2e80ce |
---|---|
91 page = self._page | 91 page = self._page |
92 source = self._sources[0] | 92 source = self._sources[0] |
93 | 93 |
94 for item in source.getAllContents(): | 94 for item in source.getAllContents(): |
95 post = app.getPage(source, item) | 95 post = app.getPage(source, item) |
96 | 96 post_dt = post.datetime |
97 year = post.datetime.strftime('%Y') | 97 |
98 month = post.datetime.strftime('%B %Y') | 98 year = post_dt.year |
99 month = (post_dt.month, post_dt.year) | |
99 | 100 |
100 posts_this_year = yearly_index.get(year) | 101 posts_this_year = yearly_index.get(year) |
101 if posts_this_year is None: | 102 if posts_this_year is None: |
102 timestamp = time.mktime( | 103 timestamp = time.mktime( |
103 (post.datetime.year, 1, 1, 0, 0, 0, 0, 0, -1)) | 104 (post_dt.year, 1, 1, 0, 0, 0, 0, 0, -1)) |
104 posts_this_year = BlogArchiveEntry( | 105 posts_this_year = BlogArchiveEntry( |
105 source, page, year, timestamp) | 106 source, page, year, timestamp) |
106 yearly_index[year] = posts_this_year | 107 yearly_index[year] = posts_this_year |
107 posts_this_year._items.append(post.content_item) | 108 posts_this_year._items.append(post.content_item) |
108 | 109 |
109 posts_this_month = monthly_index.get(month) | 110 posts_this_month = monthly_index.get(month) |
110 if posts_this_month is None: | 111 if posts_this_month is None: |
111 timestamp = time.mktime( | 112 timestamp = time.mktime( |
112 (post.datetime.year, post.datetime.month, 1, | 113 (post_dt.year, post_dt.month, 1, |
113 0, 0, 0, 0, 0, -1)) | 114 0, 0, 0, 0, 0, -1)) |
114 posts_this_month = BlogArchiveEntry( | 115 posts_this_month = BlogArchiveEntry( |
115 source, page, month, timestamp) | 116 source, page, month, timestamp) |
116 monthly_index[month] = posts_this_month | 117 monthly_index[month] = posts_this_month |
117 posts_this_month._items.append(post.content_item) | 118 posts_this_month._items.append(post.content_item) |