added LRU cache to registration queue data

v1.18.x
Julian Lam 9 years ago
parent 1783a07067
commit 5e3a114b17

@ -18,6 +18,7 @@
"autoprefixer": "^6.2.3",
"bcryptjs": "~2.3.0",
"body-parser": "^1.9.0",
"checksum": "^0.1.1",
"colors": "^1.1.0",
"compression": "^1.1.0",
"connect-ensure-login": "^0.1.1",

@ -3,6 +3,8 @@
var async = require('async');
var request = require('request');
var LRU = require('lru-cache');
var checksum = require('checksum');
var db = require('../database');
var meta = require('../meta');
@ -12,6 +14,11 @@ var groups = require('../groups');
var translator = require('../../public/src/modules/translator');
var utils = require('../../public/src/utils');
var sfsCache = LRU({
max: 500,
maxAge: 1000*60*60*24 // one day
});
module.exports = function(User) {
@ -163,6 +170,17 @@ module.exports = function(User) {
return next(null, user);
}
var sum = checksum(user.ip+user.email+user.username);
if (sfsCache.has(sum)) {
var cached = sfsCache.get(sum);
user.spamData = cached;
user.usernameSpam = cached.username.frequency > 0 || cached.username.appears > 0;
user.emailSpam = cached.email.frequency > 0 || cached.email.appears > 0;
user.ipSpam = cached.ip.frequency > 0 || cached.ip.appears > 0;
return next(null, user);
}
// temporary: see http://www.stopforumspam.com/forum/viewtopic.php?id=6392
user.ip = user.ip.replace('::ffff:', '');
@ -179,6 +197,7 @@ module.exports = function(User) {
return next(null, user);
}
if (response.statusCode === 200) {
sfsCache.set(sum, body);
user.spamData = body;
user.usernameSpam = body.username.frequency > 0 || body.username.appears > 0;
user.emailSpam = body.email.frequency > 0 || body.email.appears > 0;

Loading…
Cancel
Save