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.

CUSTOMER_REATTRIBUTION_EVENTS_LIMIT

Steven Tey9c5181579fd0
diff --git a/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts b/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts
index 9c7da5b271..780820f25c 100644
--- a/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts
+++ b/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts
@@ -2,7 +2,7 @@ import { isFirstConversion } from "@/lib/analytics/is-first-conversion";
import { createId } from "@/lib/api/create-id";
import { getCustomerOrThrow } from "@/lib/api/customers/get-customer-or-throw";
import {
- CUSTOMER_EVENTS_LIMIT,
+ CUSTOMER_REATTRIBUTION_EVENTS_LIMIT,
getCustomerReattributeEvents,
isReattributedCustomerStub,
recreateCustomerForReattribution,
@@ -34,6 +34,13 @@ export const POST = withWorkspace(
const { partnerId, linkId, createClawback } =
reattributeCustomerBodySchema.parse(await parseRequestBody(req));
+ if (workspace.id !== ACME_WORKSPACE_ID) {
+ await assertRateLimit({
+ policy: RATELIMIT_POLICIES.reattributeCustomer,
+ identifier: workspace.id,
+ });
+ }
+
const customer = await getCustomerOrThrow(
{
id,
@@ -100,17 +107,10 @@ export const POST = withWorkspace(
}),
]);
- if (events.length >= CUSTOMER_EVENTS_LIMIT) {
+ if (events.length >= CUSTOMER_REATTRIBUTION_EVENTS_LIMIT) {
throw new DubApiError({
code: "unprocessable_entity",
- message: `This customer has too many events to reattribute (limit ${CUSTOMER_EVENTS_LIMIT}).`,
- });
- }
-
- if (workspace.id !== ACME_WORKSPACE_ID) {
- await assertRateLimit({
- policy: RATELIMIT_POLICIES.reattributeCustomer,
- identifier: workspace.id,
+ message: `This customer has too many events to reattribute (limit ${CUSTOMER_REATTRIBUTION_EVENTS_LIMIT}).`,
});
}
diff --git a/apps/web/lib/api/customers/reattribute-customer.ts b/apps/web/lib/api/customers/reattribute-customer.ts
index 8854f75f3e..699dadcb37 100644
--- a/apps/web/lib/api/customers/reattribute-customer.ts
+++ b/apps/web/lib/api/customers/reattribute-customer.ts
@@ -19,7 +19,7 @@ import { nanoid } from "@dub/utils";
import { Customer, Link } from "@prisma/client";
import * as z from "zod/v4";
-export const CUSTOMER_EVENTS_LIMIT = 1000;
+export const CUSTOMER_REATTRIBUTION_EVENTS_LIMIT = 500;
const UNPAID_COMMISSION_STATUSES = ["pending", "hold", "processed"] as const;
const STATS_LOCK_TTL_SECONDS = 60 * 60 * 24;
@@ -98,7 +98,7 @@ export function isReattributedCustomerStub({
export async function getCustomerReattributeEvents(customerId: string) {
const { data } = await getCustomerEventsTB({
customerId,
- limit: CUSTOMER_EVENTS_LIMIT,
+ limit: CUSTOMER_REATTRIBUTION_EVENTS_LIMIT,
});
return (data ?? []).filter(
@@ -208,9 +208,9 @@ export async function loadReattributeEventPlan({
getCustomerReattributeEvents(newCustomerId),
]);
- if (oldEvents.length >= CUSTOMER_EVENTS_LIMIT) {
+ if (oldEvents.length >= CUSTOMER_REATTRIBUTION_EVENTS_LIMIT) {
throw new Error(
- `Customer ${oldCustomerId} has too many events to reattribute (limit ${CUSTOMER_EVENTS_LIMIT}).`,
+ `Customer ${oldCustomerId} has too many events to reattribute (limit ${CUSTOMER_REATTRIBUTION_EVENTS_LIMIT}).`,
);
}
@@ -256,9 +256,9 @@ export async function reingestCustomerEvents({
getCustomerReattributeEvents(newCustomerId),
]);
- if (oldEvents.length >= CUSTOMER_EVENTS_LIMIT) {
+ if (oldEvents.length >= CUSTOMER_REATTRIBUTION_EVENTS_LIMIT) {
throw new Error(
- `Customer ${oldCustomerId} has too many events to reattribute (limit ${CUSTOMER_EVENTS_LIMIT}).`,
+ `Customer ${oldCustomerId} has too many events to reattribute (limit ${CUSTOMER_REATTRIBUTION_EVENTS_LIMIT}).`,
);
}