mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-21 05:57:43 +01:00
Misc fixes and improvements (#6143)
* `setup` command fixes and improvements - Enable using the `./nodebb setup` command for auto-setup with a JSON argument - Change CLI so package-install and dependency install are separate steps - Fix #6142 * Prevent compiling templates multiple times - Multiple requests for same template get pooled - Hopefully fixes the "templateFunction is not a function" error which happens if site is restarted during high-traffic times * More helpful upgrade template
This commit is contained in:
committed by
Julian Lam
parent
3551d7d68e
commit
fc19f3af61
@@ -203,12 +203,19 @@ middleware.delayLoading = function (req, res, next) {
|
||||
};
|
||||
|
||||
var viewsDir = nconf.get('views_dir');
|
||||
var workingCache = {};
|
||||
|
||||
middleware.templatesOnDemand = function (req, res, next) {
|
||||
var filePath = req.filePath || path.join(viewsDir, req.path);
|
||||
if (!filePath.endsWith('.js')) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (workingCache[filePath]) {
|
||||
workingCache[filePath].push(next);
|
||||
return;
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (cb) {
|
||||
file.exists(filePath, cb);
|
||||
@@ -218,6 +225,14 @@ middleware.templatesOnDemand = function (req, res, next) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// need to check here again
|
||||
// because compilation could have started since last check
|
||||
if (workingCache[filePath]) {
|
||||
workingCache[filePath].push(next);
|
||||
return;
|
||||
}
|
||||
|
||||
workingCache[filePath] = [next];
|
||||
fs.readFile(filePath.replace(/\.js$/, '.tpl'), 'utf8', cb);
|
||||
},
|
||||
function (source, cb) {
|
||||
@@ -229,5 +244,12 @@ middleware.templatesOnDemand = function (req, res, next) {
|
||||
function (compiled, cb) {
|
||||
fs.writeFile(filePath, compiled, cb);
|
||||
},
|
||||
], next);
|
||||
], function (err) {
|
||||
var arr = workingCache[filePath];
|
||||
workingCache[filePath] = null;
|
||||
|
||||
arr.forEach(function (callback) {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user