Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-ratelimiter

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-ratelimiter - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

<a name="1.2.1"></a>
## [1.2.1](https://github.com/microlinkhq/async-ratelimiter/compare/v1.2.0...v1.2.1) (2019-03-27)
<a name="1.2.0"></a>

@@ -7,0 +12,0 @@ # [1.2.0](https://github.com/microlinkhq/async-ratelimiter/compare/v1.1.4...v1.2.0) (2019-03-27)

27

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://documentup.com/microlinkhq/async-ratelimiter",
"version": "1.2.0",
"version": "1.2.1",
"main": "src/index.js",

@@ -14,22 +14,7 @@ "author": {

"contributors": [
{
"name": "Kiko Beats",
"email": "josefrancisco.verdu@gmail.com"
},
{
"name": "Marcus Poehls",
"email": "marcus.poehls@gmail.com"
},
{
"name": "Ayan Yenbekbay",
"email": "ayan.yenb@gmail.com"
},
{
"name": "Nico Kaiser",
"email": "nico@kaiser.me"
},
{
"name": "amanda",
"email": "amandalucis@gmail.com"
}
"Kiko Beats <josefrancisco.verdu@gmail.com>",
"Marcus Poehls <marcus.poehls@gmail.com>",
"Ayan Yenbekbay <ayan.yenb@gmail.com>",
"Nico Kaiser <nico@kaiser.me>",
"amanda <amandalucis@gmail.com>"
],

@@ -36,0 +21,0 @@ "repository": {

@@ -110,4 +110,4 @@ # async-ratelimiter

*Required*</br>
Type: `string`
Default: `this.id`

@@ -114,0 +114,0 @@ The identifier to limit against (typically a user id).

@@ -27,3 +27,2 @@ 'use strict'

const { db } = this
const key = `${this.namespace}:${id}`

@@ -33,11 +32,13 @@ const now = microtime.now()

const pipeline = db.multi()
pipeline.zremrangebyscore([key, 0, start])
pipeline.zcard([key])
if (decrease) pipeline.zadd([key, now, now])
pipeline.zrange([key, 0, 0])
pipeline.zrange([key, -max, -max])
pipeline.pexpire([key, duration])
const res = await pipeline.exec()
const operations = [
['zremrangebyscore', key, 0, start],
['zcard', key],
['zrange', key, 0, 0],
['zrange', key, -max, -max],
['pexpire', key, duration]
]
if (decrease) operations.splice(2, 0, ['zadd', key, now, now])
const res = await this.db.multi(operations).exec()
const count = parseInt(res[1][1])

@@ -44,0 +45,0 @@ const oldest = parseInt(res[decrease ? 3 : 2][1])

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc