From 343ff18014a20d24368db7784c479745f950cf52 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 29 Sep 2014 19:31:27 -0400 Subject: [PATCH] closed #2179 --- app.js | 5 +++ loader.js | 27 ++++++++++++++ src/meta/css.js | 99 +++++++++++++++++++++++++++++-------------------- 3 files changed, 91 insertions(+), 40 deletions(-) diff --git a/app.js b/app.js index 46323d07fd..8ed093631e 100644 --- a/app.js +++ b/app.js @@ -168,6 +168,11 @@ function start() { meta.js.map = message.map; winston.info('[cluster] Client-side javascript and mapping propagated to worker ' + cluster.worker.id); break; + case 'css-propagate': + meta.css.cache = message.cache; + meta.css.acpCache = message.acpCache; + winston.info('[cluster] Stylesheet propagated to worker ' + cluster.worker.id); + break; } }); diff --git a/loader.js b/loader.js index 63ad8a6977..6ae585812f 100644 --- a/loader.js +++ b/loader.js @@ -14,6 +14,10 @@ var nconf = require('nconf'), js: { cache: undefined, map: undefined + }, + css: { + cache: undefined, + acpCache: undefined } }; @@ -36,6 +40,14 @@ Loader.init = function() { }); } + if (Loader.css.cache) { + worker.send({ + action: 'css-propagate', + cache: Loader.css.cache, + acpCache: Loader.css.acpCache + }); + } + worker.send('bind'); // Kill an instance in the shutdown queue @@ -69,6 +81,21 @@ Loader.init = function() { }); }); break; + case 'css-propagate': + Loader.css.cache = message.cache; + Loader.css.acpCache = message.acpCache; + + var otherWorkers = Object.keys(cluster.workers).filter(function(worker_id) { + return parseInt(worker_id, 10) !== parseInt(worker.id, 10); + }); + otherWorkers.forEach(function(worker_id) { + cluster.workers[worker_id].send({ + action: 'css-propagate', + cache: message.cache, + acpCache: message.acpCache + }); + }); + break; case 'listening': if (message.primary) { Loader.primaryWorker = parseInt(worker.id, 10); diff --git a/src/meta/css.js b/src/meta/css.js index fe2387b62f..c6ddfd876d 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -24,47 +24,66 @@ module.exports = function(Meta) { Meta.css.defaultBranding = {}; Meta.css.minify = function(callback) { - winston.info('[meta/css] Minifying LESS/CSS'); - db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) { - var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'), - baseThemePath = path.join(nconf.get('themes_path'), (themeData['theme:type'] && themeData['theme:type'] === 'local' ? themeId : 'nodebb-theme-vanilla')), - paths = [ - baseThemePath, - path.join(__dirname, '../../node_modules'), - path.join(__dirname, '../../public/vendor/fontawesome/less'), - path.join(__dirname, '../../public/vendor/bootstrap/less') - ], - source = '@import "font-awesome";', - acpSource, - x; - - - plugins.lessFiles = filterMissingFiles(plugins.lessFiles); - for(x=0; x