Skip to content

Commit

Permalink
Fixed issue with wrong compare between seconds and miliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-97 committed Nov 24, 2023
1 parent 5189be8 commit abe8fa9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/RateLimiterDynamo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit abe8fa9

Please sign in to comment.