performance: add template cache for quicker page renders

pull/4074/head
Chocobozzz 2020-06-01 16:00:47 +02:00 committed by GitHub
parent 4f37865d97
commit 59b1a2d5e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -25,6 +25,8 @@ var path = require("path");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
var resolve = require("resolve"); var resolve = require("resolve");
const templateCache = new Map()
exports.info = { exports.info = {
__output_stack: [], __output_stack: [],
block_stack: [], block_stack: [],
@ -114,12 +116,19 @@ exports.require = function (name, args, mod) {
args.e = exports; args.e = exports;
args.require = require; 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.args.push(args);
exports.info.file_stack.push({path: ejspath, inherit: []}); 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.file_stack.pop();
exports.info.args.pop(); exports.info.args.pop();