From 59b1a2d5e0fd1b3375ca0bcfc6da53d5f890d3e7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 1 Jun 2020 16:00:47 +0200 Subject: [PATCH] performance: add template cache for quicker page renders --- src/node/eejs/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/node/eejs/index.js b/src/node/eejs/index.js index 9d032840d..bfb445de2 100644 --- a/src/node/eejs/index.js +++ b/src/node/eejs/index.js @@ -25,6 +25,8 @@ var path = require("path"); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); var resolve = require("resolve"); +const templateCache = new Map() + exports.info = { __output_stack: [], block_stack: [], @@ -114,12 +116,19 @@ exports.require = function (name, args, mod) { args.e = exports; args.require = require; - var template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>'; - + + let template + if (!templateCache.has(ejspath)) { + template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>'; + templateCache.set(ejspath, template) + } else { + template = templateCache.get(ejspath) + } + exports.info.args.push(args); exports.info.file_stack.push({path: ejspath, inherit: []}); - var res = ejs.render(template, args); + var res = ejs.render(template, args, { cache: true, filename: ejspath }); exports.info.file_stack.pop(); exports.info.args.pop();