From 86d4f8e2198ed8c701baf81c024c0ef4dd931e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Wed, 14 Feb 2018 15:40:12 +0100 Subject: [PATCH] lua script v1 --- lib/cartodb/middleware/rate-limit.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/middleware/rate-limit.js b/lib/cartodb/middleware/rate-limit.js index 8ef205a5..ee4c9c78 100644 --- a/lib/cartodb/middleware/rate-limit.js +++ b/lib/cartodb/middleware/rate-limit.js @@ -50,7 +50,7 @@ module.exports = function rateLimitMiddleware (metadataBackend) { getStoreKey(user, endpointGroup), // KEY[1] getStatusKey(user, endpointGroup) // KEY[2] ]; - + metadataBackend.redisCmd(REDIS_DB, 'EVAL', redisParams, function(err, {isBloqued, limit, remaining, retry, reset}) { if (err) { return next(err); @@ -108,9 +108,9 @@ function getStatusKey(user, endpointGroup) { return USER_KEY_REDIS + user + ':' + endpointGroup; } -function getLuaScript(maxBurst, period) { +function getLuaScript() { return ` - local max = redis.call("HGETALL", KEYS[1]) - return redis.call("CL.THROTTLE", KEYS[2], ${maxBurst}, max, ${period}) + local userValues = redis.call("HGETALL", KEYS[1]) + return redis.call("CL.THROTTLE", KEYS[2], userValues[b], userValues[c], userValues[p]) `; }