diff --git a/public/language/en-GB/admin/settings/advanced.json b/public/language/en-GB/admin/settings/advanced.json index 5731a605d3..a08f863af1 100644 --- a/public/language/en-GB/admin/settings/advanced.json +++ b/public/language/en-GB/admin/settings/advanced.json @@ -32,5 +32,9 @@ "sockets.settings": "WebSocket Settings", "sockets.max-attempts": "Max Reconnection Attempts", "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)" } \ No newline at end of file diff --git a/src/analytics.js b/src/analytics.js index 8f30eaf46c..1922f5d230 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -10,6 +10,7 @@ const LRU = require('lru-cache'); const db = require('./database'); const utils = require('./utils'); const plugins = require('./plugins'); +const meta = require('./meta'); const Analytics = module.exports; @@ -21,21 +22,19 @@ let pageViewsGuest = 0; let pageViewsBot = 0; let uniqueIPCount = 0; let uniquevisitors = 0; +let ipCache; -/** - * TODO: allow the cache's max value to be configurable. On high-traffic installs, - * the cache could be exhausted continuously if there are more than 500 concurrently - * active users - */ -var ipCache = new LRU({ - max: 500, - length: function () { return 1; }, - maxAge: 0, -}); - -new cronJob('*/10 * * * * *', function () { - Analytics.writeData(); -}, null, true); +Analytics.init = async function () { + ipCache = new LRU({ + max: parseInt(meta.config['analytics:maxCache'], 10) || 500, + length: function () { return 1; }, + maxAge: 0, + }); + + new cronJob('*/10 * * * * *', function () { + Analytics.writeData(); + }, null, true); +}; Analytics.increment = function (keys, callback) { keys = Array.isArray(keys) ? keys : [keys]; diff --git a/src/views/admin/settings/advanced.tpl b/src/views/admin/settings/advanced.tpl index e1258ba058..cf1934dfc9 100644 --- a/src/views/admin/settings/advanced.tpl +++ b/src/views/admin/settings/advanced.tpl @@ -150,4 +150,19 @@ +