Skip to content

Commit 111a095

Browse files
committed
track ratelimit only on creation
1 parent 23d8001 commit 111a095

File tree

1 file changed

+9
-3
lines changed
  • packages/service-utils/src/core/rateLimit

1 file changed

+9
-3
lines changed

packages/service-utils/src/core/rateLimit/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ export async function rateLimit(args: {
7171
limitPerSecond * sampleRate * RATE_LIMIT_WINDOW_SECONDS;
7272

7373
if (requestCount > limitPerWindow) {
74-
// Report rate limit hits.
75-
if (project?.id) {
76-
await updateRateLimitedAt(project.id, serviceConfig);
74+
/**
75+
* Report rate limit hits.
76+
* Only track rate limit when its hit for the first time.
77+
* Not waiting for tracking to complete as user doesn't need to wait.
78+
*/
79+
if (requestCount === 1 && project?.id) {
80+
updateRateLimitedAt(project.id, serviceConfig).catch(() => {
81+
// no-op
82+
});
7783
}
7884

7985
// Reject requests when they've exceeded 2x the rate limit.

0 commit comments

Comments
 (0)