Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/service-utils/src/core/rateLimit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ export async function rateLimit(args: {
limitPerSecond * sampleRate * RATE_LIMIT_WINDOW_SECONDS;

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

// Reject requests when they've exceeded 2x the rate limit.
Expand Down
Loading