mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-15 02:21:46 +02:00
Merge branch 'develop' into activitypub
This commit is contained in:
@@ -1,12 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const cacheCreate = require('../cache/lru');
|
||||
const meta = require('../meta');
|
||||
let cache = null;
|
||||
|
||||
module.exports = cacheCreate({
|
||||
name: 'post',
|
||||
maxSize: meta.config.postCacheSize,
|
||||
sizeCalculation: function (n) { return n.length || 1; },
|
||||
ttl: 0,
|
||||
enabled: global.env === 'production',
|
||||
});
|
||||
exports.getOrCreate = function () {
|
||||
if (!cache) {
|
||||
const cacheCreate = require('../cache/lru');
|
||||
const meta = require('../meta');
|
||||
cache = cacheCreate({
|
||||
name: 'post',
|
||||
maxSize: meta.config.postCacheSize,
|
||||
sizeCalculation: function (n) { return n.length || 1; },
|
||||
ttl: 0,
|
||||
enabled: global.env === 'production',
|
||||
});
|
||||
}
|
||||
|
||||
return cache;
|
||||
};
|
||||
|
||||
exports.del = function (pid) {
|
||||
if (cache) {
|
||||
cache.del(pid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.reset = function () {
|
||||
if (cache) {
|
||||
cache.reset();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ const meta = require('../meta');
|
||||
const plugins = require('../plugins');
|
||||
const translator = require('../translator');
|
||||
const utils = require('../utils');
|
||||
const postCache = require('./cache');
|
||||
|
||||
let sanitizeConfig = {
|
||||
allowedTags: sanitize.defaults.allowedTags.concat([
|
||||
@@ -49,13 +50,15 @@ module.exports = function (Posts) {
|
||||
if (!postData) {
|
||||
return postData;
|
||||
}
|
||||
|
||||
if (!type || !allowedTypes.has(type)) {
|
||||
type = 'default';
|
||||
}
|
||||
postData.content = String(postData.sourceContent || postData.content || '');
|
||||
const cache = require('./cache');
|
||||
const cache = postCache.getOrCreate();
|
||||
const cacheKey = `${String(postData.pid)}|${type}`;
|
||||
const cachedContent = cache.get(cacheKey);
|
||||
|
||||
if (postData.pid && cachedContent !== undefined) {
|
||||
postData.content = cachedContent;
|
||||
return postData;
|
||||
|
||||
Reference in New Issue
Block a user