pluginfw/performance: Dont cache if max age is 0 (#4098)

pull/4105/head
John McLear 2020-06-08 17:21:55 +01:00 committed by GitHub
parent 3e78b79d9d
commit 93829b9e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -24,6 +24,7 @@ var fs = require("fs");
var path = require("path"); 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");
var settings = require('../utils/Settings');
const templateCache = new Map() const templateCache = new Map()
@ -118,17 +119,24 @@ exports.require = function (name, args, mod) {
args.require = require; args.require = require;
let template let template
if (!templateCache.has(ejspath)) { if (settings.maxAge !== 0){ // don't cache if maxAge is 0
if (!templateCache.has(ejspath)) {
template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
templateCache.set(ejspath, template)
} else {
template = templateCache.get(ejspath)
}
}else{
template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>'; 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: []});
if(settings.maxAge !== 0){
var res = ejs.render(template, args, { cache: true, filename: ejspath }); var res = ejs.render(template, args, { cache: true, filename: ejspath });
}else{
var res = ejs.render(template, args, { cache: false, filename: ejspath });
}
exports.info.file_stack.pop(); exports.info.file_stack.pop();
exports.info.args.pop(); exports.info.args.pop();