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.

use EXISTS instead of JOIN like

Steven Tey41575ee64b2e
diff --git a/apps/web/lib/api/partners/get-partners.ts b/apps/web/lib/api/partners/get-partners.ts
index d0c530fe9f..9a88a3a6ff 100644
--- a/apps/web/lib/api/partners/get-partners.ts
+++ b/apps/web/lib/api/partners/get-partners.ts
@@ -107,7 +107,20 @@ export async function getPartners(filters: PartnerFilters) {
${tenantId ? Prisma.sql`AND pe.tenantId = ${tenantId}` : Prisma.sql``}
${country ? Prisma.sql`AND p.country = ${country}` : Prisma.sql``}
${rewardId ? Prisma.sql`AND EXISTS (SELECT 1 FROM PartnerReward pr WHERE pr.programEnrollmentId = pe.id AND pr.rewardId = ${rewardId})` : Prisma.sql``}
- ${search ? Prisma.sql`AND (LOWER(p.name) LIKE LOWER(${`%${search}%`}) OR LOWER(p.email) LIKE LOWER(${`%${search}%`})) OR l.shortLink LIKE LOWER(${`%${search}%`})` : Prisma.sql``}
+ ${
+ search
+ ? Prisma.sql`AND (
+ LOWER(p.name) LIKE LOWER(${`%${search}%`})
+ OR LOWER(p.email) LIKE LOWER(${`%${search}%`})
+ OR EXISTS (
+ SELECT 1 FROM Link searchLink
+ WHERE searchLink.programId = ${program.id}
+ AND searchLink.partnerId = p.id
+ AND searchLink.shortLink LIKE LOWER(${`%${search}%`})
+ )
+ )`
+ : Prisma.sql``
+ }
${ids && ids.length > 0 ? Prisma.sql`AND pe.partnerId IN (${Prisma.join(ids)})` : Prisma.sql``}
GROUP BY
p.id, pe.id, metrics.totalClicks, metrics.totalLeads, metrics.totalSales, metrics.totalSaleAmount