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.

early return if clickId is cached

Steven Teye67b2a452833
diff --git a/apps/web/app/api/track/visit/route.ts b/apps/web/app/api/track/visit/route.ts
index 2fdfd8f43c..84fbcd35ed 100644
--- a/apps/web/app/api/track/visit/route.ts
+++ b/apps/web/app/api/track/visit/route.ts
@@ -41,16 +41,18 @@ export const POST = withAxiom(async (req: AxiomRequest) => {
const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;
- let [cachedClickId, cachedLink] = await redis.mget<
- [string, RedisLinkProps]
- >([
+ let [clickId, cachedLink] = await redis.mget<[string, RedisLinkProps]>([
clickCache._createKey({ domain, key, ip }),
linkCache._createKey({ domain, key }),
]);
- // assign a new clickId if there's no cached clickId
- // else, reuse the cached clickId
- const clickId = cachedClickId ?? nanoid(16);
+ // if the clickId is already cached in Redis, return it
+ if (clickId) {
+ return NextResponse.json({ clickId }, { headers: CORS_HEADERS });
+ }
+
+ // Otherwise, track the visit event
+ clickId = nanoid(16);
if (!cachedLink) {
const link = await getLinkViaEdge({