mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-07 22:03:24 +02:00
run tasks in series to speed up startup time
This commit is contained in:
22
src/meta.js
22
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) {
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user