From 5e3a114b17b3fe738efc9c841e5905a5e740552e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 28 Mar 2016 19:55:40 -0400 Subject: [PATCH] added LRU cache to registration queue data --- package.json | 1 + src/user/approval.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/package.json b/package.json index 9adf788c69..5289968835 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/user/approval.js b/src/user/approval.js index 41237043eb..273ad3a3a2 100644 --- a/src/user/approval.js +++ b/src/user/approval.js @@ -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;