From abe8fa9e7dd3f3a020040ef622411e118e14ef33 Mon Sep 17 00:00:00 2001 From: daniele Date: Fri, 24 Nov 2023 19:50:04 +0100 Subject: [PATCH] Fixed issue with wrong compare between seconds and miliseconds --- lib/RateLimiterDynamo.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/RateLimiterDynamo.js b/lib/RateLimiterDynamo.js index 8d27917..dca5cf8 100644 --- a/lib/RateLimiterDynamo.js +++ b/lib/RateLimiterDynamo.js @@ -221,6 +221,7 @@ class RateLimiterDynamo extends RateLimiterStoreAbstract { } const dateNow = Date.now(); + const dateNowSec = dateNow / 1000; /* -1 means never expire, DynamoDb do not support null values in number fields. DynamoDb TTL use unix timestamp in seconds. */ @@ -249,7 +250,7 @@ class RateLimiterDynamo extends RateLimiterStoreAbstract { ExpressionAttributeValues: { ':new_points': {N: points.toString()}, ':new_expire': {N: newExpireSec.toString()}, - ':where_expire': {N: dateNow.toString()} + ':where_expire': {N: dateNowSec.toString()} }, ConditionExpression: 'expire <= :where_expire OR attribute_not_exists(points)', ReturnValues: 'ALL_NEW' @@ -263,7 +264,7 @@ class RateLimiterDynamo extends RateLimiterStoreAbstract { UpdateExpression: 'SET points = points + :new_points', ExpressionAttributeValues: { ':new_points': {N: points.toString()}, - ':where_expire': {N: dateNow.toString()} + ':where_expire': {N: dateNowSec.toString()} }, ConditionExpression: 'expire > :where_expire', ReturnValues: 'ALL_NEW'