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.

Duplicate link conversions on concurrent track/sale requests (#4076)

Pedro Ladeira32834f696893
diff --git a/apps/web/lib/api/conversions/track-sale.ts b/apps/web/lib/api/conversions/track-sale.ts
index 4856ead27d..c92feaa1ae 100644
--- a/apps/web/lib/api/conversions/track-sale.ts
+++ b/apps/web/lib/api/conversions/track-sale.ts
@@ -499,11 +499,26 @@ const _trackSale = async ({
metadata: metadata ? JSON.stringify(metadata) : "",
};
- const firstConversionFlag = isFirstConversion({
+ let firstConversionFlag = isFirstConversion({
customer,
linkId: saleData.link_id,
});
+ // Deduplicate concurrent first sales for the same customer + link so only one
+ // request is counted as the first conversion.
+ if (firstConversionFlag) {
+ const claim = await redis.set(
+ `firstConversion:${customer.id}:${saleData.link_id}`,
+ 1,
+ {
+ ex: 30,
+ nx: true,
+ },
+ );
+
+ firstConversionFlag = claim !== null;
+ }
+
waitUntil(
(async () => {
// Update link conversions, sales, and saleAmount