diff --git a/app.js b/app.js index 4ce28da224..7a222b930c 100644 --- a/app.js +++ b/app.js @@ -28,7 +28,6 @@ if (require.main !== module) { var nconf = require('nconf'); nconf.argv().env({ separator: '__', - lowerCase: true, }); var url = require('url'); diff --git a/loader.js b/loader.js index f2a511336b..a2df1b33b7 100644 --- a/loader.js +++ b/loader.js @@ -142,7 +142,7 @@ function getPorts() { process.exit(); } var urlObject = url.parse(_url); - var port = nconf.get('port') || urlObject.port || 4567; + var port = nconf.get('PORT') || nconf.get('port') || urlObject.port || 4567; if (!Array.isArray(port)) { port = [port]; } diff --git a/package.json b/package.json index e86db2e69d..c70d09bc93 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "ipaddr.js": "^1.5.4", "jimp": "0.2.28", "jquery": "^3.2.1", + "jsesc": "2.5.1", "json-2-csv": "^2.1.2", "less": "^2.7.2", "lodash": "^4.17.4", @@ -57,7 +58,7 @@ "mousetrap": "^1.6.1", "nconf": "^0.8.5", "nodebb-plugin-composer-default": "6.0.1", - "nodebb-plugin-dbsearch": "2.0.6", + "nodebb-plugin-dbsearch": "2.0.8", "nodebb-plugin-emoji-extended": "1.1.1", "nodebb-plugin-emoji-one": "1.2.1", "nodebb-plugin-markdown": "8.2.0", diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.js index a3ce7fba21..4de2045518 100644 --- a/src/controllers/admin/cache.js +++ b/src/controllers/admin/cache.js @@ -2,6 +2,8 @@ var cacheController = module.exports; +var utils = require('../../utils'); + cacheController.get = function (req, res) { var postCache = require('../../posts/cache'); var groupCache = require('../../groups').cache; @@ -38,6 +40,9 @@ cacheController.get = function (req, res) { itemCount: objectCache.itemCount, percentFull: ((objectCache.length / objectCache.max) * 100).toFixed(2), dump: req.query.debug ? JSON.stringify(objectCache.dump(), null, 4) : false, + hits: utils.addCommas(String(objectCache.hits)), + misses: utils.addCommas(String(objectCache.misses)), + missRatio: (1 - (objectCache.hits / (objectCache.hits + objectCache.misses))).toFixed(4), }; } diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.js index 4985afec2f..becfb83a2f 100644 --- a/src/database/mongo/hash.js +++ b/src/database/mongo/hash.js @@ -13,6 +13,8 @@ module.exports = function (db, module) { maxAge: 0, }); + cache.misses = 0; + cache.hits = 0; module.objectCache = cache; pubsub.on('mongo:hash:cache:del', function (key) { @@ -86,9 +88,14 @@ module.exports = function (db, module) { } var nonCachedKeys = keys.filter(function (key) { - return !cache.get(key); + return cache.get(key) === undefined; }); + var hits = keys.length - nonCachedKeys.length; + var misses = keys.length - hits; + cache.hits += hits; + cache.misses += misses; + if (!nonCachedKeys.length) { return getFromCache(callback); } @@ -98,12 +105,9 @@ module.exports = function (db, module) { return callback(err); } - data.forEach(function (objectData) { - if (objectData) { - var key = objectData._key; - delete objectData._key; - cache.set(key, objectData); - } + var map = helpers.toMap(data); + nonCachedKeys.forEach(function (key) { + cache.set(key, map[key] || null); }); getFromCache(callback); diff --git a/src/middleware/header.js b/src/middleware/header.js index 4b667ad954..3824ff6fc3 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -2,6 +2,7 @@ var async = require('async'); var nconf = require('nconf'); +var jsesc = require('jsesc'); var db = require('../database'); var user = require('../user'); @@ -60,7 +61,7 @@ module.exports = function (middleware) { bodyClass: data.bodyClass, }; - templateValues.configJSON = JSON.stringify(res.locals.config); + templateValues.configJSON = jsesc(JSON.stringify(res.locals.config), { isScriptContext: true }); async.waterfall([ function (next) { @@ -124,7 +125,7 @@ module.exports = function (middleware) { results.user.isGlobalMod = results.isGlobalMod; results.user.isMod = !!results.isModerator; results.user.uid = parseInt(results.user.uid, 10); - results.user.email = String(results.user.email).replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + results.user.email = String(results.user.email); results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1; results.user.isEmailConfirmSent = !!results.isEmailConfirmSent; @@ -138,7 +139,7 @@ module.exports = function (middleware) { templateValues.isGlobalMod = results.user.isGlobalMod; templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod; templateValues.user = results.user; - templateValues.userJSON = JSON.stringify(results.user); + templateValues.userJSON = jsesc(JSON.stringify(results.user), { isScriptContext: true }); templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS; templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : ''; templateValues.useCustomHTML = parseInt(meta.config.useCustomHTML, 10) === 1; diff --git a/src/start.js b/src/start.js index 0fbdcb4ae8..b7084dabde 100644 --- a/src/start.js +++ b/src/start.js @@ -98,7 +98,7 @@ function setupConfigs() { nconf.set('secure', urlObject.protocol === 'https:'); nconf.set('use_port', !!urlObject.port); nconf.set('relative_path', relativePath); - nconf.set('port', urlObject.port || nconf.get('port') || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567); + nconf.set('port', nconf.get('PORT') || nconf.get('port') || urlObject.port || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567); nconf.set('upload_url', '/assets/uploads'); } diff --git a/src/views/admin/advanced/cache.tpl b/src/views/admin/advanced/cache.tpl index 1ea4aa39d9..1c2d98ca93 100644 --- a/src/views/admin/advanced/cache.tpl +++ b/src/views/admin/advanced/cache.tpl @@ -30,15 +30,20 @@
Object Cache
+ +
{objectCache.length} / {objectCache.max}
-
[[admin/advanced/cache:percent-full, {objectCache.percentFull}]]
+ {objectCache.hits}
+ {objectCache.misses}
+ {objectCache.missRatio}
+
{objectCache.dump}
diff --git a/src/webserver.js b/src/webserver.js index 2564642ade..bfc472b8ea 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -252,7 +252,7 @@ function setupAutoLocale(app, callback) { function listen(callback) { callback = callback || function () { }; - var port = parseInt(nconf.get('port'), 10); + var port = nconf.get('port'); var isSocket = isNaN(port); var socketPath = isSocket ? nconf.get('port') : ''; @@ -270,7 +270,7 @@ function listen(callback) { process.exit(); } } - + port = parseInt(port, 10); if ((port !== 80 && port !== 443) || nconf.get('trust_proxy') === true) { winston.info('Enabling \'trust proxy\''); app.enable('trust proxy');