Skip to content

Node.js based forum software built for the modern web

run tasks in series to speed up startup time

psychobunnyacd24d856f7b
diff --git a/src/meta.js b/src/meta.js
index 716d90e9cb..ffc85c98bf 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -61,20 +61,16 @@ var async = require('async'),
async.apply(plugins.clearRequireCache),
async.apply(plugins.reload),
async.apply(plugins.reloadRoutes),
+ async.apply(Meta.css.minify),
+ async.apply(Meta.js.minify, 'nodebb.min.js'),
+ async.apply(Meta.js.minify, 'acp.min.js'),
+ async.apply(Meta.sounds.init),
+ async.apply(Meta.templates.compile),
+ async.apply(auth.reloadRoutes),
function(next) {
- async.parallel([
- async.apply(Meta.js.minify, 'nodebb.min.js'),
- async.apply(Meta.js.minify, 'acp.min.js'),
- async.apply(Meta.css.minify),
- async.apply(Meta.sounds.init),
- async.apply(Meta.templates.compile),
- async.apply(auth.reloadRoutes),
- function(next) {
- Meta.config['cache-buster'] = utils.generateUUID();
- templates.flush();
- next();
- }
- ], next);
+ Meta.config['cache-buster'] = utils.generateUUID();
+ templates.flush();
+ next();
}
], function(err) {
if (!err) {
diff --git a/src/meta/css.js b/src/meta/css.js
index 9688f880c9..9307389b3b 100644
--- a/src/meta/css.js
+++ b/src/meta/css.js
@@ -150,7 +150,7 @@ module.exports = function(Meta) {
});
}
- Meta.css.commitToFile = function(filename) {
+ Meta.css.commitToFile = function(filename, callback) {
var file = (filename === 'acpCache' ? 'admin' : 'stylesheet') + '.css';
fs.writeFile(path.join(__dirname, '../../public/' + file), Meta.css[filename], function(err) {
@@ -160,6 +160,8 @@ module.exports = function(Meta) {
winston.error('[meta/css] ' + err.message);
process.exit(0);
}
+
+ callback();
});
};
@@ -195,7 +197,11 @@ module.exports = function(Meta) {
// Save the compiled CSS in public/ so things like nginx can serve it
if (nconf.get('isPrimary') === 'true') {
- Meta.css.commitToFile(destination);
+ return Meta.css.commitToFile(destination, function() {
+ if (typeof callback === 'function') {
+ callback(null, result.css);
+ }
+ });
}
if (typeof callback === 'function') {
diff --git a/src/meta/js.js b/src/meta/js.js
index f2fabac6ac..7ee5f0eb17 100644
--- a/src/meta/js.js
+++ b/src/meta/js.js
@@ -89,6 +89,8 @@ module.exports = function(Meta) {
return;
}
+ winston.verbose('[meta/js] Minifying ' + target);
+
var forkProcessParams = setupDebugging();
var minifier = Meta.js.minifierProc = fork('minifier.js', [], forkProcessParams);
@@ -119,11 +121,12 @@ module.exports = function(Meta) {
});
}
- Meta.js.commitToFile(target);
+ Meta.js.commitToFile(target, function() {
+ if (typeof callback === 'function') {
+ callback();
+ }
+ });
- if (typeof callback === 'function') {
- callback();
- }
break;
case 'error':
winston.error('[meta/js] Could not compile ' + target + ': ' + message.message);
@@ -185,7 +188,7 @@ module.exports = function(Meta) {
}
};
- Meta.js.commitToFile = function(target) {
+ Meta.js.commitToFile = function(target, callback) {
fs.writeFile(path.join(__dirname, '../../public/' + target), Meta.js.target[target].cache, function (err) {
if (err) {
winston.error('[meta/js] ' + err.message);
@@ -194,6 +197,7 @@ module.exports = function(Meta) {
winston.verbose('[meta/js] ' + target + ' committed to disk.');
emitter.emit('meta:js.compiled');
+ callback();
});
};
diff --git a/src/webserver.js b/src/webserver.js
index 1db202e520..057c9a5e8a 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -85,7 +85,7 @@ function initializeNodeBB(callback) {
plugins.init(app, middleware, next);
},
function(next) {
- async.parallel([
+ async.series([
async.apply(meta.templates.compile),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'nodebb.min.js'),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'acp.min.js'),