Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

deduplicate

Steven Teyd44e084f17c1
diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.ts
index 4180f9e7cd..ceb3b45420 100644
--- a/apps/web/app/api/track/lead/route.ts
+++ b/apps/web/app/api/track/lead/route.ts
@@ -28,18 +28,16 @@ export const POST = withWorkspaceEdge(
metadata,
} = trackLeadRequestSchema.parse(await parseRequestBody(req));
- // if in production / preview env, deduplicate lead events – only record 1 event per hour
- if (process.env.VERCEL === "1") {
- const { success } = await ratelimit(2, "1 h").limit(
- `recordLead:${externalId}:${eventName.toLowerCase().replace(" ", "-")}`,
- );
+ // deduplicate lead events – only record 1 event per hour
+ const { success } = await ratelimit(1, "1 h").limit(
+ `recordLead:${externalId}:${eventName.toLowerCase().replace(" ", "-")}`,
+ );
- if (!success) {
- throw new DubApiError({
- code: "rate_limit_exceeded",
- message: `Rate limit exceeded for customer ${externalId}: ${eventName}`,
- });
- }
+ if (!success) {
+ throw new DubApiError({
+ code: "rate_limit_exceeded",
+ message: `Rate limit exceeded for customer ${externalId}: ${eventName}`,
+ });
}
// Find click event
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index ae55d869f4..ce07f7a70b 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -38,14 +38,12 @@ export async function recordClick({
const referer = req.headers.get("referer");
const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;
const identity_hash = await getIdentityHash(req);
- // if in production / preview env, deduplicate clicks from the same IP address + link ID – only record 1 click per hour
- if (process.env.VERCEL === "1") {
- const { success } = await ratelimit(2, "1 h").limit(
- `recordClick:${ip}:${linkId}`,
- );
- if (!success) {
- return null;
- }
+ // deduplicate clicks from the same IP address + link ID – only record 1 click per hour
+ const { success } = await ratelimit(1, "1 h").limit(
+ `recordClick:${ip}:${linkId}`,
+ );
+ if (!success) {
+ return null;
}
return await Promise.allSettled([