|
7 | 7 | import { EU_COUNTRY_CODES } from "@dub/utils/src/constants/countries";
|
8 | 8 | import { geolocation, ipAddress } from "@vercel/functions";
|
9 | 9 | import { userAgent } from "next/server";
|
| 10 | +import { clickCache } from "../api/links/click-cache"; |
10 | 11 | import { ExpandedLink, transformLink } from "../api/links/utils/transform-link";
|
11 | 12 | import {
|
12 | 13 | detectBot,
|
@@ -67,13 +68,11 @@ export async function recordClick({
|
67 | 68 |
|
68 | 69 | const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;
|
69 | 70 |
|
70 |
| - const cacheKey = `recordClick:${domain}:${key}:${ip}`; |
71 |
| - |
72 | 71 | // by default, we deduplicate clicks for a domain + key pair from the same IP address – only record 1 click per hour
|
73 | 72 | // we only need to do these if skipRatelimit is not true (we skip it in /api/track/:path endpoints)
|
74 | 73 | if (!skipRatelimit) {
|
75 | 74 | // here, we check if the clickId is cached in Redis within the last hour
|
76 |
| - const cachedClickId = await redis.get<string>(cacheKey); |
| 75 | + const cachedClickId = await clickCache.get({ domain, key, ip }); |
77 | 76 | if (cachedClickId) {
|
78 | 77 | return null;
|
79 | 78 | }
|
@@ -153,9 +152,7 @@ export async function recordClick({
|
153 | 152 | ).then((res) => res.json()),
|
154 | 153 |
|
155 | 154 | // cache the click ID in Redis for 1 hour
|
156 |
| - redis.set(cacheKey, clickId, { |
157 |
| - ex: 60 * 60, |
158 |
| - }), |
| 155 | + clickCache.set({ domain, key, ip, clickId }), |
159 | 156 |
|
160 | 157 | // cache the click data for 5 mins
|
161 | 158 | // we're doing this because ingested click events are not available immediately in Tinybird
|
|
0 commit comments