mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
fix: #8884, remove header/footer cache
This commit is contained in:
@@ -9,7 +9,6 @@ cacheController.get = function (req, res) {
|
|||||||
const groupCache = require('../../groups').cache;
|
const groupCache = require('../../groups').cache;
|
||||||
const objectCache = require('../../database').objectCache;
|
const objectCache = require('../../database').objectCache;
|
||||||
const localCache = require('../../cache');
|
const localCache = require('../../cache');
|
||||||
const headerFooterCache = require('../../middleware').headerFooterCache;
|
|
||||||
|
|
||||||
function getInfo(cache) {
|
function getInfo(cache) {
|
||||||
return {
|
return {
|
||||||
@@ -28,7 +27,6 @@ cacheController.get = function (req, res) {
|
|||||||
postCache: getInfo(postCache),
|
postCache: getInfo(postCache),
|
||||||
groupCache: getInfo(groupCache),
|
groupCache: getInfo(groupCache),
|
||||||
localCache: getInfo(localCache),
|
localCache: getInfo(localCache),
|
||||||
headerFooterCache: getInfo(headerFooterCache),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (objectCache) {
|
if (objectCache) {
|
||||||
@@ -44,7 +42,6 @@ cacheController.dump = function (req, res, next) {
|
|||||||
object: require('../../database').objectCache,
|
object: require('../../database').objectCache,
|
||||||
group: require('../../groups').cache,
|
group: require('../../groups').cache,
|
||||||
local: require('../../cache'),
|
local: require('../../cache'),
|
||||||
headerfooter: require('../../middleware').headerFooterCache,
|
|
||||||
};
|
};
|
||||||
if (!caches[req.query.name]) {
|
if (!caches[req.query.name]) {
|
||||||
return next();
|
return next();
|
||||||
|
|||||||
@@ -10,19 +10,10 @@ const translator = require('../translator');
|
|||||||
const widgets = require('../widgets');
|
const widgets = require('../widgets');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const slugify = require('../slugify');
|
const slugify = require('../slugify');
|
||||||
const cacheCreate = require('../cacheCreate');
|
|
||||||
const cache = cacheCreate({
|
|
||||||
name: 'header-footer',
|
|
||||||
max: 1000,
|
|
||||||
maxAge: 0,
|
|
||||||
enabled: global.env === 'production',
|
|
||||||
});
|
|
||||||
|
|
||||||
const relative_path = nconf.get('relative_path');
|
const relative_path = nconf.get('relative_path');
|
||||||
|
|
||||||
module.exports = function (middleware) {
|
module.exports = function (middleware) {
|
||||||
middleware.headerFooterCache = cache;
|
|
||||||
|
|
||||||
middleware.processRender = function processRender(req, res, next) {
|
middleware.processRender = function processRender(req, res, next) {
|
||||||
// res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
|
// res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
|
||||||
const render = res.render;
|
const render = res.render;
|
||||||
@@ -104,21 +95,6 @@ module.exports = function (middleware) {
|
|||||||
|
|
||||||
async function renderHeaderFooter(method, req, res, options) {
|
async function renderHeaderFooter(method, req, res, options) {
|
||||||
let str = '';
|
let str = '';
|
||||||
const lang = getLang(req, res);
|
|
||||||
function getCacheKey() {
|
|
||||||
return [lang, method]
|
|
||||||
.concat(req.path.split('/').slice(0, 4))
|
|
||||||
.join('/');
|
|
||||||
}
|
|
||||||
let cacheKey;
|
|
||||||
if (req.uid === 0 && res.locals.renderHeader) {
|
|
||||||
cacheKey = getCacheKey();
|
|
||||||
str = cache.get(cacheKey);
|
|
||||||
if (str) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!str) {
|
|
||||||
if (res.locals.renderHeader) {
|
if (res.locals.renderHeader) {
|
||||||
str = await middleware[method](req, res, options);
|
str = await middleware[method](req, res, options);
|
||||||
} else if (res.locals.renderAdminHeader) {
|
} else if (res.locals.renderAdminHeader) {
|
||||||
@@ -126,12 +102,7 @@ module.exports = function (middleware) {
|
|||||||
} else {
|
} else {
|
||||||
str = '';
|
str = '';
|
||||||
}
|
}
|
||||||
}
|
return await translate(str, getLang(req, res));
|
||||||
const translated = await translate(str, lang);
|
|
||||||
if (req.uid === 0 && res.locals.renderHeader) {
|
|
||||||
cache.set(cacheKey, translated, 300000);
|
|
||||||
}
|
|
||||||
return translated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLang(req, res) {
|
function getLang(req, res) {
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ SocketCache.clear = async function (socket, data) {
|
|||||||
require('../../groups').cache.reset();
|
require('../../groups').cache.reset();
|
||||||
} else if (data.name === 'local') {
|
} else if (data.name === 'local') {
|
||||||
require('../../cache').reset();
|
require('../../cache').reset();
|
||||||
} else if (data.name === 'headerfooter') {
|
|
||||||
require('../../middleware').headerFooterCache.reset();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +20,6 @@ SocketCache.toggle = async function (socket, data) {
|
|||||||
object: require('../../database').objectCache,
|
object: require('../../database').objectCache,
|
||||||
group: require('../../groups').cache,
|
group: require('../../groups').cache,
|
||||||
local: require('../../cache'),
|
local: require('../../cache'),
|
||||||
headerfooter: require('../../middleware').headerFooterCache,
|
|
||||||
};
|
};
|
||||||
if (!caches[data.name]) {
|
if (!caches[data.name]) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="row post-cache">
|
<div class="row post-cache">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-2">
|
<div class="col-lg-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">[[admin/advanced/cache:post-cache]]</div>
|
<div class="panel-heading">[[admin/advanced/cache:post-cache]]</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- IF objectCache -->
|
<!-- IF objectCache -->
|
||||||
<div class="col-lg-2">
|
<div class="col-lg-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Object Cache</div>
|
<div class="panel-heading">Object Cache</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- ENDIF objectCache -->
|
<!-- ENDIF objectCache -->
|
||||||
|
|
||||||
<div class="col-lg-2">
|
<div class="col-lg-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Group Cache</div>
|
<div class="panel-heading">Group Cache</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-2">
|
<div class="col-lg-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Local Cache</div>
|
<div class="panel-heading">Local Cache</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@@ -114,32 +114,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-2">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">Header Footer Cache</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<div class="checkbox" data-name="headerfooter">
|
|
||||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
|
||||||
<input class="mdl-switch__input" type="checkbox" {{{if headerFooterCache.enabled}}}checked{{{end}}}>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<span>{headerFooterCache.length} / {headerFooterCache.max}</span><br/>
|
|
||||||
|
|
||||||
<div class="progress">
|
|
||||||
<div class="progress-bar" role="progressbar" aria-valuenow="{headerFooterCache.percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {headerFooterCache.percentFull}%;">
|
|
||||||
[[admin/advanced/cache:percent-full, {headerFooterCache.percentFull}]]
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label>Hits:</label> <span>{headerFooterCache.hits}</span><br/>
|
|
||||||
<label>Misses:</label> <span>{headerFooterCache.misses}</span><br/>
|
|
||||||
<label>Hit Ratio:</label> <span>{headerFooterCache.hitRatio}</span><br/>
|
|
||||||
<a href="{config.relative_path}/api/admin/advanced/cache/dump?name=headerfooter" class="btn btn-sm btn-default"><i class="fa fa-download"></i></a>
|
|
||||||
<a class="btn btn-sm btn-danger clear" data-name="headerfooter"><i class="fa fa-trash"></i></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ async function setupMockDefaults() {
|
|||||||
require('../../src/groups').cache.reset();
|
require('../../src/groups').cache.reset();
|
||||||
require('../../src/posts/cache').reset();
|
require('../../src/posts/cache').reset();
|
||||||
require('../../src/cache').reset();
|
require('../../src/cache').reset();
|
||||||
require('../../src/middleware').headerFooterCache.reset();
|
|
||||||
|
|
||||||
winston.info('test_database flushed');
|
winston.info('test_database flushed');
|
||||||
await setupDefaultConfigs(meta);
|
await setupDefaultConfigs(meta);
|
||||||
|
|||||||
Reference in New Issue
Block a user