diff 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
line wrap: on
line diff
--- a/piecrust/dataproviders/blog.py	Thu Jun 15 07:30:44 2017 -0700
+++ b/piecrust/dataproviders/blog.py	Thu Jun 15 07:31:50 2017 -0700
@@ -93,14 +93,15 @@
 
         for item in source.getAllContents():
             post = app.getPage(source, item)
+            post_dt = post.datetime
 
-            year = post.datetime.strftime('%Y')
-            month = post.datetime.strftime('%B %Y')
+            year = post_dt.year
+            month = (post_dt.month, post_dt.year)
 
             posts_this_year = yearly_index.get(year)
             if posts_this_year is None:
                 timestamp = time.mktime(
-                    (post.datetime.year, 1, 1, 0, 0, 0, 0, 0, -1))
+                    (post_dt.year, 1, 1, 0, 0, 0, 0, 0, -1))
                 posts_this_year = BlogArchiveEntry(
                     source, page, year, timestamp)
                 yearly_index[year] = posts_this_year
@@ -109,7 +110,7 @@
             posts_this_month = monthly_index.get(month)
             if posts_this_month is None:
                 timestamp = time.mktime(
-                    (post.datetime.year, post.datetime.month, 1,
+                    (post_dt.year, post_dt.month, 1,
                      0, 0, 0, 0, 0, -1))
                 posts_this_month = BlogArchiveEntry(
                     source, page, month, timestamp)