Skip to content

Commit b7a6278

Browse files
committed
optimize algo + fix loading state
1 parent e8d5778 commit b7a6278

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/network/page-client.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ function PartnerCard({
338338
) : (
339339
<Globe className="size-3.5 shrink-0" />
340340
),
341-
text: partner?.country ? COUNTRIES[partner.country] : "Planet Earth",
341+
text: partner
342+
? partner.country
343+
? COUNTRIES[partner.country]
344+
: "Planet Earth"
345+
: undefined,
342346
},
343347
{
344348
id: "joinedAt",

apps/web/lib/api/network/calculate-partner-ranking.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function calculatePartnerRanking({
103103
status === "discover"
104104
? starred === true
105105
? Prisma.sql`dp.starredAt ASC`
106-
: Prisma.sql`finalScore DESC, ${hasProfileCheck} DESC, p.id ASC`
106+
: Prisma.sql`finalScore DESC, p.id ASC`
107107
: status === "invited"
108108
? Prisma.sql`dp.invitedAt ASC`
109109
: Prisma.sql`enrolled.createdAt DESC, p.id ASC`;
@@ -232,10 +232,16 @@ export async function calculatePartnerRanking({
232232
CASE WHEN enrolled.status = 'approved' THEN enrolled.createdAt ELSE NULL END as recruitedAt,
233233
preferredEarningStructuresData.preferredEarningStructures as preferredEarningStructures,
234234
salesChannelsData.salesChannels as salesChannels,
235+
236+
-- Pre-compute hasProfileCheck for faster sorting
237+
${hasProfileCheck} as hasProfile,
235238
236-
-- FINAL SCORE (0-265+ points): Similarity-based ranking for discovery
239+
-- FINAL SCORE (0-765+ points): Similarity-based ranking for discovery
237240
-- Trusted partners (trustedAt IS NOT NULL) get 200 bonus points to rank at the top
241+
-- Partners with profiles get 500 bonus points to ensure they rank above those without profiles
238242
(
243+
-- Profile bonus: 500 points for partners with online presence (ensures they rank above those without)
244+
CASE WHEN ${hasProfileCheck} THEN 500 ELSE 0 END +
239245
-- Trusted partner bonus: 200 points for partners with trustedAt set
240246
CASE WHEN p.trustedAt IS NOT NULL THEN 200 ELSE 0 END +
241247
COALESCE(similarProgramMetrics.similarityScore, 0) +

0 commit comments

Comments
 (0)