Commit 2c8c936b authored by Yusei Tahara's avatar Yusei Tahara

jinja2_template.py: Compile the same source only once and use compiled source next time.

compile function takes a lot of time, thus this change saves time when the same source is used many times in apache frontend SR.
parent ea79037a
......@@ -155,6 +155,7 @@ def get_umask():
get_umask = lambda: umask
return umask
compiled_source_cache = {}
class Recipe(object):
def __init__(self, buildout, name, options):
......@@ -223,8 +224,18 @@ class Recipe(object):
with open(template, 'rb') as f:
source = f.read().decode(self.encoding)
env = self.env
# get compiled source
if template == '<inline>':
compiled_source = env.compile(source, filename=template)
else:
try:
compiled_source = compiled_source_cache[template]
except KeyError:
compiled_source_cache[template] = compiled_source = env.compile(source, filename=template)
template = env.template_class.from_code(env,
env.compile(source, filename=template),
compiled_source,
env.make_globals(None), None)
rendered = template.render(**self.context).encode(self.encoding)
mode = self.mode
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment