-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Use identityHash for recordClickCache #2943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughReplaces IP-based deduplication and cache keying with identityHash across tracking routes, middleware, record-click cache API, and Tinybird recording; updates function signatures and cache key construction, and includes identity_hash in event payloads. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Route as Edge/API Route
participant ID as getIdentityHash
participant Cache as recordClickCache (Redis)
participant TB as Tinybird
rect rgba(230,240,255,0.5)
Client->>Route: POST /track (click/open/visit)
Route->>ID: getIdentityHash(req)
ID-->>Route: identityHash
Route->>Cache: get({domain,key,identityHash})
alt Cache hit
Cache-->>Route: cached clickId/link
Route-->>Client: 200 with cached result
else Cache miss
Route->>TB: recordClick(req, identityHash)
TB->>Cache: set({domain,key,identityHash,clickId})
TB-->>Route: recorded clickId/payload
Route-->>Client: 200 with result
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/web/app/(ee)/api/track/click/route.ts(2 hunks)apps/web/app/(ee)/api/track/open/route.ts(3 hunks)apps/web/app/(ee)/api/track/visit/route.ts(2 hunks)apps/web/lib/api/links/record-click-cache.ts(1 hunks)apps/web/lib/middleware/link.ts(3 hunks)apps/web/lib/tinybird/record-click.ts(3 hunks)
🔇 Additional comments (6)
apps/web/app/(ee)/api/track/open/route.ts (1)
6-6: LGTM! identityHash integration is correct.The migration from IP-based to identityHash-based cache keys is properly implemented:
getIdentityHashis imported and called- The result is used in
recordClickCache._createKeyfor cached click lookupNote: The
deepLinkClickCache(lines 32-56) still uses IP-based keys, which appears to be intentional as it's a separate caching mechanism for deep link data.Also applies to: 29-29, 75-75
apps/web/app/(ee)/api/track/visit/route.ts (1)
7-7: LGTM! Clean migration to identityHash.The changes correctly implement the identityHash-based cache keying:
- Proper import of
getIdentityHash- Removed unused
LOCALHOST_IPandipAddressimports- identityHash is computed and used in
recordClickCache._createKeyThe migration is clean and consistent with other track routes.
Also applies to: 12-13, 37-37, 40-40
apps/web/lib/middleware/link.ts (1)
5-5: LGTM! Middleware correctly migrated to identityHash.The middleware properly implements identityHash-based cache lookups:
getIdentityHashimported and called conditionally whenshouldCacheClickIdis true- identityHash is used in
recordClickCache.getfor cached click retrieval- The
geolocationimport remains as it's still needed for geo-targeting logic (separate from cache keying)The conditional computation of identityHash (only when needed) is efficient.
Also applies to: 253-256
apps/web/app/(ee)/api/track/click/route.ts (1)
11-11: LGTM! Track click route properly migrated.The changes implement identityHash-based cache keying correctly:
getIdentityHashis imported from the correct path- Unused
LOCALHOST_IPandipAddressimports removed- identityHash is computed and used in
recordClickCache._createKeyThe migration is consistent with other track routes.
Also applies to: 19-20, 56-56, 61-61
apps/web/lib/tinybird/record-click.ts (1)
87-87: LGTM! Complete migration to identityHash-based deduplication.The record-click function correctly implements identityHash-based deduplication:
- identityHash is computed early (line 87)
- Used for deduplication checks via
recordClickCache.get(lines 93-97)- Used for caching via
recordClickCache.set(line 186)- Added to the analytics payload as
identity_hash(line 131)Note: IP is still collected (line 122) and conditionally included in the analytics payload (lines 135-137) based on EU country logic. This is intentional and correct—IP is used for analytics but not for deduplication.
Also applies to: 93-97, 186-186
apps/web/lib/api/links/record-click-cache.ts (1)
13-26: identityHash always supplied
The sole call to recordClickCache.set uses getIdentityHash(req), which always returns a non-empty SHA256 string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/lib/api/links/record-click-cache.ts (1)
34-36: Consider validating identityHash format.While the current implementation is correct, consider adding validation to ensure
identityHashis non-empty and doesn't contain problematic characters (e.g., colons that could interfere with the key structure). However, this validation may be better placed at the caller level whereidentityHashis generated.Example validation in
_createKey:_createKey({ domain, key, identityHash }: KeyProps) { + if (!identityHash || identityHash.includes(':')) { + throw new Error('Invalid identityHash for cache key'); + } return `recordClick:${domain}:${key}:${identityHash}`; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/lib/api/links/record-click-cache.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/lib/api/links/record-click-cache.ts (2)
apps/web/lib/upstash/redis.ts (1)
redis(4-7)apps/web/lib/api/links/cache.ts (1)
CACHE_EXPIRATION(11-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
apps/web/lib/api/links/record-click-cache.ts (2)
6-10: Previous concern addressed: identityHash is now required.The
identityHashproperty is now typed asstring(non-optional), which resolves the cache key collision concern raised in the previous review. This ensures that every cache key will have a valid identityHash component.
13-36: LGTM! Clean refactor from IP to identityHash.All method signatures (
set,get,_createKey) have been consistently updated to useidentityHashinstead ofip. The cache key formatrecordClick:${domain}:${key}:${identityHash}is well-structured and appropriately scoped.Note: During deployment, old IP-based cache entries will become inaccessible and new identityHash-based entries will be created. This is acceptable given the 1-hour TTL—existing entries will expire naturally without impacting functionality.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Privacy