mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: analytics:maxCache setting in ACP
I removed a TODO from core. Watch your head as flying pigs are abound
This commit is contained in:
@@ -32,5 +32,9 @@
|
|||||||
"sockets.settings": "WebSocket Settings",
|
"sockets.settings": "WebSocket Settings",
|
||||||
"sockets.max-attempts": "Max Reconnection Attempts",
|
"sockets.max-attempts": "Max Reconnection Attempts",
|
||||||
"sockets.default-placeholder": "Default: %1",
|
"sockets.default-placeholder": "Default: %1",
|
||||||
"sockets.delay": "Reconnection Delay"
|
"sockets.delay": "Reconnection Delay",
|
||||||
|
|
||||||
|
"analytics.settings": "Analytics Settings",
|
||||||
|
"analytics.max-cache": "Analytics Cache Max Value",
|
||||||
|
"analytics.max-cache-help": "On high-traffic installs, the cache could be exhausted continuously if there are more concurrent active users than the Max Cache value. (Restart required)"
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ const LRU = require('lru-cache');
|
|||||||
const db = require('./database');
|
const db = require('./database');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const plugins = require('./plugins');
|
const plugins = require('./plugins');
|
||||||
|
const meta = require('./meta');
|
||||||
|
|
||||||
const Analytics = module.exports;
|
const Analytics = module.exports;
|
||||||
|
|
||||||
@@ -21,14 +22,11 @@ let pageViewsGuest = 0;
|
|||||||
let pageViewsBot = 0;
|
let pageViewsBot = 0;
|
||||||
let uniqueIPCount = 0;
|
let uniqueIPCount = 0;
|
||||||
let uniquevisitors = 0;
|
let uniquevisitors = 0;
|
||||||
|
let ipCache;
|
||||||
|
|
||||||
/**
|
Analytics.init = async function () {
|
||||||
* TODO: allow the cache's max value to be configurable. On high-traffic installs,
|
ipCache = new LRU({
|
||||||
* the cache could be exhausted continuously if there are more than 500 concurrently
|
max: parseInt(meta.config['analytics:maxCache'], 10) || 500,
|
||||||
* active users
|
|
||||||
*/
|
|
||||||
var ipCache = new LRU({
|
|
||||||
max: 500,
|
|
||||||
length: function () { return 1; },
|
length: function () { return 1; },
|
||||||
maxAge: 0,
|
maxAge: 0,
|
||||||
});
|
});
|
||||||
@@ -36,6 +34,7 @@ var ipCache = new LRU({
|
|||||||
new cronJob('*/10 * * * * *', function () {
|
new cronJob('*/10 * * * * *', function () {
|
||||||
Analytics.writeData();
|
Analytics.writeData();
|
||||||
}, null, true);
|
}, null, true);
|
||||||
|
};
|
||||||
|
|
||||||
Analytics.increment = function (keys, callback) {
|
Analytics.increment = function (keys, callback) {
|
||||||
keys = Array.isArray(keys) ? keys : [keys];
|
keys = Array.isArray(keys) ? keys : [keys];
|
||||||
|
|||||||
@@ -150,4 +150,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/advanced:analytics.settings]]</div>
|
||||||
|
<div class="col-sm-10 col-xs-12">
|
||||||
|
<form>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="analytics:maxCache">[[admin/settings/advanced:analytics.max-cache]]</label>
|
||||||
|
<input class="form-control" id="analytics:maxCache" type="text" value="500" placeholder="500" data-field="analytics:maxCache" />
|
||||||
|
<p class="help-block">
|
||||||
|
[[admin/settings/advanced:analytics.max-cache-help]]
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- IMPORT admin/partials/settings/footer.tpl -->
|
<!-- IMPORT admin/partials/settings/footer.tpl -->
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ var helmet = require('helmet');
|
|||||||
|
|
||||||
var Benchpress = require('benchpressjs');
|
var Benchpress = require('benchpressjs');
|
||||||
var db = require('./database');
|
var db = require('./database');
|
||||||
|
var analytics = require('./analytics');
|
||||||
var file = require('./file');
|
var file = require('./file');
|
||||||
var emailer = require('./emailer');
|
var emailer = require('./emailer');
|
||||||
var meta = require('./meta');
|
var meta = require('./meta');
|
||||||
@@ -105,6 +106,7 @@ async function initializeNodeBB() {
|
|||||||
await routes(app, middleware);
|
await routes(app, middleware);
|
||||||
await meta.blacklist.load();
|
await meta.blacklist.load();
|
||||||
await flags.init();
|
await flags.init();
|
||||||
|
await analytics.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupExpressApp(app) {
|
function setupExpressApp(app) {
|
||||||
|
|||||||
Reference in New Issue
Block a user