2016-09-14 21:00:41 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
const cacheController = module.exports;
|
2016-09-14 21:00:41 +03:00
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
const utils = require('../../utils');
|
2017-10-25 18:20:44 -04:00
|
|
|
|
2017-02-18 15:05:36 -07:00
|
|
|
cacheController.get = function (req, res) {
|
2019-08-13 10:36:48 -04:00
|
|
|
const postCache = require('../../posts/cache');
|
|
|
|
|
const groupCache = require('../../groups').cache;
|
|
|
|
|
const objectCache = require('../../database').objectCache;
|
|
|
|
|
const localCache = require('../../cache');
|
2016-09-14 21:00:41 +03:00
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
let percentFull = 0;
|
2016-09-14 21:00:41 +03:00
|
|
|
if (postCache.itemCount > 0) {
|
|
|
|
|
percentFull = ((postCache.length / postCache.max) * 100).toFixed(2);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
const data = {
|
2016-09-14 21:00:41 +03:00
|
|
|
postCache: {
|
|
|
|
|
length: postCache.length,
|
|
|
|
|
max: postCache.max,
|
|
|
|
|
itemCount: postCache.itemCount,
|
|
|
|
|
percentFull: percentFull,
|
2018-10-15 15:03:06 -04:00
|
|
|
hits: utils.addCommas(String(postCache.hits)),
|
|
|
|
|
misses: utils.addCommas(String(postCache.misses)),
|
|
|
|
|
hitRatio: ((postCache.hits / (postCache.hits + postCache.misses) || 0)).toFixed(4),
|
2020-11-06 23:13:12 -05:00
|
|
|
enabled: postCache.enabled,
|
2016-09-14 21:00:41 +03:00
|
|
|
},
|
|
|
|
|
groupCache: {
|
|
|
|
|
length: groupCache.length,
|
|
|
|
|
max: groupCache.max,
|
|
|
|
|
itemCount: groupCache.itemCount,
|
|
|
|
|
percentFull: ((groupCache.length / groupCache.max) * 100).toFixed(2),
|
2018-10-15 13:45:55 -04:00
|
|
|
hits: utils.addCommas(String(groupCache.hits)),
|
|
|
|
|
misses: utils.addCommas(String(groupCache.misses)),
|
|
|
|
|
hitRatio: (groupCache.hits / (groupCache.hits + groupCache.misses)).toFixed(4),
|
2020-11-06 23:13:12 -05:00
|
|
|
enabled: groupCache.enabled,
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2018-11-27 19:38:28 -05:00
|
|
|
localCache: {
|
|
|
|
|
length: localCache.length,
|
|
|
|
|
max: localCache.max,
|
|
|
|
|
itemCount: localCache.itemCount,
|
|
|
|
|
percentFull: ((localCache.length / localCache.max) * 100).toFixed(2),
|
|
|
|
|
hits: utils.addCommas(String(localCache.hits)),
|
|
|
|
|
misses: utils.addCommas(String(localCache.misses)),
|
2020-07-29 12:50:18 -04:00
|
|
|
hitRatio: ((localCache.hits / (localCache.hits + localCache.misses) || 0)).toFixed(4),
|
2020-11-06 23:13:12 -05:00
|
|
|
enabled: localCache.enabled,
|
2018-11-27 19:38:28 -05:00
|
|
|
},
|
2017-10-23 18:31:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (objectCache) {
|
|
|
|
|
data.objectCache = {
|
|
|
|
|
length: objectCache.length,
|
|
|
|
|
max: objectCache.max,
|
|
|
|
|
itemCount: objectCache.itemCount,
|
|
|
|
|
percentFull: ((objectCache.length / objectCache.max) * 100).toFixed(2),
|
2017-10-25 18:20:44 -04:00
|
|
|
hits: utils.addCommas(String(objectCache.hits)),
|
|
|
|
|
misses: utils.addCommas(String(objectCache.misses)),
|
2017-12-14 14:18:56 -05:00
|
|
|
hitRatio: (objectCache.hits / (objectCache.hits + objectCache.misses)).toFixed(4),
|
2020-11-06 23:13:12 -05:00
|
|
|
enabled: objectCache.enabled,
|
2017-10-23 18:31:16 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.render('admin/advanced/cache', data);
|
2016-09-14 21:00:41 +03:00
|
|
|
};
|
2020-11-06 23:13:12 -05:00
|
|
|
|
|
|
|
|
cacheController.dump = function (req, res, next) {
|
|
|
|
|
const caches = {
|
|
|
|
|
post: require('../../posts/cache'),
|
|
|
|
|
object: require('../../database').objectCache,
|
|
|
|
|
group: require('../../groups').cache,
|
|
|
|
|
local: require('../../cache'),
|
|
|
|
|
};
|
|
|
|
|
if (!caches[req.query.name]) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = JSON.stringify(caches[req.query.name].dump(), null, 4);
|
|
|
|
|
res.setHeader('Content-disposition', 'attachment; filename= ' + req.query.name + '-cache.json');
|
|
|
|
|
res.setHeader('Content-type', 'application/json');
|
|
|
|
|
res.write(data, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
res.end();
|
|
|
|
|
});
|
|
|
|
|
};
|