From 0cef65c4e11cad754d8d2eabda1422b513f882be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 31 Dec 2012 16:50:11 +0100 Subject: [PATCH] Add a cache for post reading during blog generation --- generators/generator.py | 4 ++-- generators/index.py | 21 +++++++++++++-------- models.py | 3 ++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/generators/generator.py b/generators/generator.py index 574efa3..2a70bf7 100644 --- a/generators/generator.py +++ b/generators/generator.py @@ -14,7 +14,6 @@ class StrictUTF8Writer(codecs.StreamWriter): def __init__(self): self.value = u'' - pass def write(self, object): object = object.replace('<', '<') @@ -41,9 +40,10 @@ class DynastieGenerator: report = '' somethingWrote = False - def __init__(self): + def __init__(self, hash_posts=None): self.report = '' self.somethingWrote = False + self.hash_posts = hash_posts def addReport(self, string, color=''): if color != '': diff --git a/generators/index.py b/generators/index.py index 4b4e2e3..362eb16 100644 --- a/generators/index.py +++ b/generators/index.py @@ -98,9 +98,13 @@ class Index(DynastieGenerator): self.addError('File does not exists ' + filename) return - f = open(filename, 'rb') - post_content = f.read() - f.close() + if self.hash_posts is None or not filename in self.hash_posts: + f = open(filename, 'rb') + post_content = f.read() + f.close() + self.hash_posts[filename] = post_content + else: + post_content = self.hash_posts[filename] while True: start = post_content.find('