mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-24 07:31:15 +01:00
Merge remote-tracking branch 'refs/remotes/origin/master' into develop
This commit is contained in:
1
app.js
1
app.js
@@ -28,7 +28,6 @@ if (require.main !== module) {
|
||||
var nconf = require('nconf');
|
||||
nconf.argv().env({
|
||||
separator: '__',
|
||||
lowerCase: true,
|
||||
});
|
||||
|
||||
var url = require('url');
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -30,15 +30,20 @@
|
||||
<div class="panel-heading"><i class="fa fa-calendar-o"></i> Object Cache</div>
|
||||
<div class="panel-body">
|
||||
|
||||
|
||||
|
||||
<label>[[admin/advanced/cache:length-to-max]]</label><br/>
|
||||
<span>{objectCache.length} / {objectCache.max}</span><br/>
|
||||
|
||||
<div class="progress">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="{objectCache.percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {objectCache.percentFull}%;">
|
||||
[[admin/advanced/cache:percent-full, {objectCache.percentFull}]]
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label>Hits:</label> <span>{objectCache.hits}</span><br/>
|
||||
<label>Misses:</label> <span>{objectCache.misses}</span><br/>
|
||||
<label>Miss Ratio:</label> <span>{objectCache.missRatio}</span><br/>
|
||||
|
||||
<!-- IF objectCache.dump -->
|
||||
<pre>{objectCache.dump}</pre>
|
||||
<!-- ENDIF objectCache.dump -->
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user