mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
cache parsed post content
clear cache on plugin install/uninstall/activate/deactivate
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
"heapdump": "^0.3.0",
|
||||
"less": "^2.0.0",
|
||||
"logrotate-stream": "^0.2.3",
|
||||
"lru-cache": "^2.5.0",
|
||||
"mime": "^1.3.4",
|
||||
"mkdirp": "~0.5.0",
|
||||
"mmmagic": "^0.3.13",
|
||||
|
||||
@@ -14,7 +14,14 @@ var winston = require('winston'),
|
||||
utils = require('../public/src/utils'),
|
||||
plugins = require('./plugins'),
|
||||
events = require('./events'),
|
||||
meta = require('./meta');
|
||||
meta = require('./meta'),
|
||||
LRU = require('lru-cache');
|
||||
|
||||
var cache = LRU({
|
||||
max: 1048576,
|
||||
length: function (n) { return n.length },
|
||||
maxAge: 1000 * 60 * 60
|
||||
});
|
||||
|
||||
(function(PostTools) {
|
||||
|
||||
@@ -100,6 +107,7 @@ var winston = require('winston'),
|
||||
});
|
||||
},
|
||||
postData: function(next) {
|
||||
cache.del(postData.pid);
|
||||
PostTools.parsePost(postData, data.uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
@@ -148,6 +156,7 @@ var winston = require('winston'),
|
||||
}
|
||||
|
||||
if (isDelete) {
|
||||
cache.del(postData.pid);
|
||||
posts.delete(pid, callback);
|
||||
} else {
|
||||
posts.restore(pid, function(err, postData) {
|
||||
@@ -165,7 +174,7 @@ var winston = require('winston'),
|
||||
if (err || !canEdit) {
|
||||
return callback(err || new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
cache.del(pid);
|
||||
posts.purge(pid, callback);
|
||||
});
|
||||
};
|
||||
@@ -173,8 +182,18 @@ var winston = require('winston'),
|
||||
PostTools.parsePost = function(postData, uid, callback) {
|
||||
postData.content = postData.content || '';
|
||||
|
||||
var cachedContent = cache.get(postData.pid);
|
||||
if (cachedContent) {
|
||||
postData.content = cachedContent;
|
||||
return callback(null, postData);
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:parse.post', {postData: postData, uid: uid}, function(err, data) {
|
||||
callback(err, data ? data.postData : null);
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
cache.set(data.postData.pid, data.postData.content);
|
||||
callback(null, data.postData);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -184,4 +203,8 @@ var winston = require('winston'),
|
||||
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
||||
};
|
||||
|
||||
PostTools.resetCache = function() {
|
||||
cache.reset();
|
||||
};
|
||||
|
||||
}(exports));
|
||||
|
||||
@@ -104,10 +104,12 @@ SocketAdmin.themes.updateBranding = function(socket, data, callback) {
|
||||
};
|
||||
|
||||
SocketAdmin.plugins.toggleActive = function(socket, plugin_id, callback) {
|
||||
require('../postTools').resetCache();
|
||||
plugins.toggleActive(plugin_id, callback);
|
||||
};
|
||||
|
||||
SocketAdmin.plugins.toggleInstall = function(socket, data, callback) {
|
||||
require('../postTools').resetCache();
|
||||
plugins.toggleInstall(data.id, data.version, callback);
|
||||
};
|
||||
|
||||
@@ -121,7 +123,7 @@ SocketAdmin.plugins.orderActivePlugins = function(socket, data, callback) {
|
||||
db.sortedSetAdd('plugins:active', plugin.order || 0, plugin.name, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
}, callback);
|
||||
};
|
||||
|
||||
@@ -339,12 +341,12 @@ SocketAdmin.getMoreFlags = function(socket, data, callback) {
|
||||
posts.getUserFlags(byUsername, sortBy, socket.uid, start, end, function(err, posts) {
|
||||
callback(err, {posts: posts, next: end + 1});
|
||||
});
|
||||
} else {
|
||||
} else {
|
||||
var set = sortBy === 'count' ? 'posts:flags:count' : 'posts:flagged';
|
||||
posts.getFlags(set, socket.uid, start, end, function(err, posts) {
|
||||
callback(err, {posts: posts, next: end + 1});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SocketAdmin.takeHeapSnapshot = function(socket, data, callback) {
|
||||
|
||||
Reference in New Issue
Block a user