Skip to content

Conversation

devkiran
Copy link
Collaborator

@devkiran devkiran commented Oct 18, 2025

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed duplicate link creation during affiliate partner imports by preventing redundant operations.
  • Improvements

    • Enhanced affiliate coupon filtering logic for more accurate partner mapping.
    • Added tracking information to generated affiliate coupon links for improved visibility.

Copy link
Contributor

vercel bot commented Oct 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 18, 2025 10:11am

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Walkthrough

The pull request modifies the Rewardful import flow to enhance affiliate coupon processing and link creation. Changes include filtering coupons by partner existence, adding partner validation, reversing the link creation condition to prevent duplicates, and attaching descriptive comments to generated links.

Changes

Cohort / File(s) Summary
Coupon filtering and link generation
apps/web/lib/rewardful/import-affiliate-coupons.ts
Filters affiliate coupons to include only those with corresponding partners in Dub; builds affiliate-ID-to-coupons mapping from filtered set. Replaces archived-active coupon filtering with direct all-coupon mapping. Adds non-null assertions for program domain/URL. Introduces ProcessedLinkProps type and adds "Link created for coupon {token}" comments to each generated link. Adds guard to execute bulk creation only when links exist.
Duplicate link prevention
apps/web/lib/rewardful/import-partners.ts
Reverses link creation condition to only create links when programEnrollment.links is empty, preventing duplicate link creation. Moves bulkCreateLinks call inside the empty-check block instead of executing unconditionally.

Sequence Diagram(s)

sequenceDiagram
    participant ImportFlow
    participant CouplonFilter as Coupon Filter
    participant PartnerCheck as Partner Validation
    participant LinkCreation as Link Creation
    participant BulkOps as Bulk Operations

    rect rgb(200, 220, 255)
    note right of ImportFlow: OLD: Unconditional link creation
    ImportFlow->>LinkCreation: Create links
    LinkCreation->>BulkOps: bulkCreateLinks (always)
    end

    rect rgb(200, 255, 220)
    note right of ImportFlow: NEW: Conditional creation with filtering
    ImportFlow->>CouplonFilter: Filter coupons by partner
    CouplonFilter->>PartnerCheck: Validate partner exists in Dub
    PartnerCheck->>LinkCreation: Only if links empty
    LinkCreation->>BulkOps: bulkCreateLinks (if links to create)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes involve logic modifications across two related files with new filtering conditions and type usage (ProcessedLinkProps), but the scope is contained to the Rewardful import flow. The filtering logic and reversed condition require careful verification against existing behavior, but the changes follow consistent patterns.

Possibly related PRs

  • dubinc/dub#2963: Directly modifies the same Rewardful import files (import-affiliate-coupons.ts and import-partners.ts), affecting coupon mapping and partner link creation logic.
  • dubinc/dub#2555: Changes partner link creation flow and introduces ProcessedLinkProps type usage in the same bulkCreateLinks code path.
  • dubinc/dub#2880: Modifies import-partners.ts link creation flow to address duplicate prevention in partner enrollment.

Suggested reviewers

  • steven-tey
  • TWilson023

Poem

🐰 The coupons hop through filters fine,
Partners matched to each design,
No more duplicates we'll create,
Links now guard against their fate!
Comments whisper "coupon born,"
Rewardful imports, well-adorned.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title "Fix Rewardful import" is related to the changeset in that both modified files are in the Rewardful import module and the changes do address issues in this area. However, the title is overly vague and generic—it uses "Fix" without explaining what specific problem is being addressed. While a developer would understand this relates to Rewardful import work, scanning through commit history they wouldn't clearly understand what the actual issue was or what aspect was corrected. The changes appear to involve preventing duplicate link creation and improving filtering logic, but the title conveys none of this detail. Consider using a more specific and descriptive title that explains what is actually being fixed, such as "Prevent duplicate link creation in Rewardful import" or "Fix Rewardful affiliate coupon filtering and link creation logic". This would help reviewers and future maintainers quickly understand the nature of the fix without having to examine the code changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-rewardful-import

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e68b491 and c30bc01.

📒 Files selected for processing (2)
  • apps/web/lib/rewardful/import-affiliate-coupons.ts (3 hunks)
  • apps/web/lib/rewardful/import-partners.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-06T07:59:03.120Z
Learnt from: devkiran
PR: dubinc/dub#2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.

Applied to files:

  • apps/web/lib/rewardful/import-partners.ts
  • apps/web/lib/rewardful/import-affiliate-coupons.ts
🧬 Code graph analysis (2)
apps/web/lib/rewardful/import-partners.ts (1)
apps/web/lib/api/links/bulk-create-links.ts (1)
  • bulkCreateLinks (18-236)
apps/web/lib/rewardful/import-affiliate-coupons.ts (2)
apps/web/lib/types.ts (1)
  • ProcessedLinkProps (313-318)
apps/web/lib/api/links/bulk-create-links.ts (1)
  • bulkCreateLinks (18-236)
⏰ 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 (4)
apps/web/lib/rewardful/import-affiliate-coupons.ts (4)

58-74: Good improvement: filtering coupons by partner existence.

This change ensures that links are only created for coupons where the corresponding partner exists in Dub, preventing orphaned links and potential errors downstream.


84-86: Defensive check is technically unnecessary but adds safety.

The partnerId check is defensive programming since filteredCoupons (line 59) already filters by partners that exist in filteredPartners. However, this guard protects against potential future changes and makes the code more resilient.


99-99: Good addition: descriptive comments for tracking.

Adding the comments field with the coupon token provides useful context for each generated link, making it easier to trace back to the original Rewardful coupon.


105-109: Good practice: guard clause for bulk operations.

Wrapping the bulkCreateLinks call in a length check prevents unnecessary function calls when there are no links to create, improving efficiency and aligning with the pattern used in bulkCreateLinks itself (which also returns early if links.length === 0).

@steven-tey steven-tey merged commit 32f5818 into main Oct 18, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the fix-rewardful-import branch October 18, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants