Skip to content

Commit 8c1dae0

Browse files
authored
feat: add reset() method to clear rate limit state for a given IP [ GSSOC '26 ] (JhaSourav07#1168)
## Description Fixes JhaSourav07#1165 Adds a `reset(ip)` method to `RateLimiter` that clears the request count for a given IP by calling `cache.delete(ip)`. This allows rate limit state to be cleared immediately after a successful authentication or admin action, without waiting for TTL expiry. Depends on the `delete()` method added to `TTLCache` in the previous contribution. ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — internal rate limiting logic, no visual output. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. - [ ] (Recommended) I joined the CommitPulse Discord community.
2 parents 83e2fed + 74b5299 commit 8c1dae0

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lib/rate-limit.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ export class RateLimiter {
4646
this.cache.set(ip, current + 1, this.windowMs);
4747
return true;
4848
}
49+
/**
50+
* Resets the request count for a given IP address.
51+
*
52+
* Useful for clearing rate limit state after a successful
53+
* authentication or admin action.
54+
*
55+
* @param ip - The IP address to reset.
56+
*
57+
* @example
58+
* rateLimiter.reset("192.168.1.1");
59+
*/
60+
reset(ip: string): void {
61+
this.cache.delete(ip);
62+
}
4963
}
5064

5165
// Global instance for track-user endpoint (5 requests per IP per minute)

0 commit comments

Comments
 (0)