From 72c90ea98fdacdbfd80b2cc2663fc1aa25364303 Mon Sep 17 00:00:00 2001 From: CahidArda Date: Wed, 3 Apr 2024 09:29:43 +0300 Subject: [PATCH 1/2] fix sliding window and bucket scripts --- src/lua-scripts/single.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua-scripts/single.ts b/src/lua-scripts/single.ts index 3582e69..a1f0812 100644 --- a/src/lua-scripts/single.ts +++ b/src/lua-scripts/single.ts @@ -32,7 +32,7 @@ export const slidingWindowScript = ` end local percentageInCurrent = ( now % window ) / window -- weighted requests to consider from the previous window - requestsInPreviousWindow = math.floor(( incrementBy - percentageInCurrent ) * requestsInPreviousWindow) + requestsInPreviousWindow = math.floor(( 1 - percentageInCurrent ) * requestsInPreviousWindow) if requestsInPreviousWindow + requestsInCurrentWindow >= tokens then return -1 end @@ -87,7 +87,7 @@ export const tokenBucketScript = ` `; export const cachedFixedWindowScript = ` - local key = KEYS[1 + local key = KEYS[1] local window = ARGV[1] local incrementBy = ARGV[2] -- increment rate per request at a given value, default is 1 From 3bf3ea2fc0f0af56236abc6cb23dace7c8d4c4ef Mon Sep 17 00:00:00 2001 From: CahidArda Date: Wed, 3 Apr 2024 12:19:27 +0300 Subject: [PATCH 2/2] fix rate limit import --- examples/with-vercel-kv/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-vercel-kv/app/page.tsx b/examples/with-vercel-kv/app/page.tsx index 2d8dce4..62e7cf3 100644 --- a/examples/with-vercel-kv/app/page.tsx +++ b/examples/with-vercel-kv/app/page.tsx @@ -1,4 +1,4 @@ -import { Ratelimit } from "../../../src"; +import { Ratelimit } from "@upstash/ratelimit"; import kv from "@vercel/kv"; import { Inter } from "next/font/google"; import { headers } from "next/headers";