mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +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",
|
"heapdump": "^0.3.0",
|
||||||
"less": "^2.0.0",
|
"less": "^2.0.0",
|
||||||
"logrotate-stream": "^0.2.3",
|
"logrotate-stream": "^0.2.3",
|
||||||
|
"lru-cache": "^2.5.0",
|
||||||
"mime": "^1.3.4",
|
"mime": "^1.3.4",
|
||||||
"mkdirp": "~0.5.0",
|
"mkdirp": "~0.5.0",
|
||||||
"mmmagic": "^0.3.13",
|
"mmmagic": "^0.3.13",
|
||||||
|
|||||||
@@ -14,7 +14,14 @@ var winston = require('winston'),
|
|||||||
utils = require('../public/src/utils'),
|
utils = require('../public/src/utils'),
|
||||||
plugins = require('./plugins'),
|
plugins = require('./plugins'),
|
||||||
events = require('./events'),
|
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) {
|
(function(PostTools) {
|
||||||
|
|
||||||
@@ -100,6 +107,7 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
postData: function(next) {
|
postData: function(next) {
|
||||||
|
cache.del(postData.pid);
|
||||||
PostTools.parsePost(postData, data.uid, next);
|
PostTools.parsePost(postData, data.uid, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
@@ -148,6 +156,7 @@ var winston = require('winston'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDelete) {
|
if (isDelete) {
|
||||||
|
cache.del(postData.pid);
|
||||||
posts.delete(pid, callback);
|
posts.delete(pid, callback);
|
||||||
} else {
|
} else {
|
||||||
posts.restore(pid, function(err, postData) {
|
posts.restore(pid, function(err, postData) {
|
||||||
@@ -165,7 +174,7 @@ var winston = require('winston'),
|
|||||||
if (err || !canEdit) {
|
if (err || !canEdit) {
|
||||||
return callback(err || new Error('[[error:no-privileges]]'));
|
return callback(err || new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
cache.del(pid);
|
||||||
posts.purge(pid, callback);
|
posts.purge(pid, callback);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -173,8 +182,18 @@ var winston = require('winston'),
|
|||||||
PostTools.parsePost = function(postData, uid, callback) {
|
PostTools.parsePost = function(postData, uid, callback) {
|
||||||
postData.content = postData.content || '';
|
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) {
|
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);
|
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PostTools.resetCache = function() {
|
||||||
|
cache.reset();
|
||||||
|
};
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|||||||
@@ -104,10 +104,12 @@ SocketAdmin.themes.updateBranding = function(socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketAdmin.plugins.toggleActive = function(socket, plugin_id, callback) {
|
SocketAdmin.plugins.toggleActive = function(socket, plugin_id, callback) {
|
||||||
|
require('../postTools').resetCache();
|
||||||
plugins.toggleActive(plugin_id, callback);
|
plugins.toggleActive(plugin_id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketAdmin.plugins.toggleInstall = function(socket, data, callback) {
|
SocketAdmin.plugins.toggleInstall = function(socket, data, callback) {
|
||||||
|
require('../postTools').resetCache();
|
||||||
plugins.toggleInstall(data.id, data.version, callback);
|
plugins.toggleInstall(data.id, data.version, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user