The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Feature/partner-search: sync tenant ID edits to the index (#4483)
Rafi506cccb0c4f6
diff --git a/apps/web/lib/actions/partners/update-partner-enrollment.ts b/apps/web/lib/actions/partners/update-partner-enrollment.tsindex 7e51d6ae9c..8eb98a3521 100644--- a/apps/web/lib/actions/partners/update-partner-enrollment.ts+++ b/apps/web/lib/actions/partners/update-partner-enrollment.ts@@ -3,6 +3,7 @@import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";import { includeProgramEnrollment } from "@/lib/api/links/include-program-enrollment";import { includeTags } from "@/lib/api/links/include-tags";+import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";import { throwIfExistingTenantEnrollmentExists } from "@/lib/api/partners/throw-if-existing-tenant-id-exists";import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";@@ -95,6 +96,10 @@ export const updatePartnerEnrollmentAction = authActionClientwaitUntil(Promise.allSettled([recordLink(programEnrollment.links),+ // Queue an index update because the tenant ID changed+ ...(tenantId !== existingTenantId+ ? [queuePartnerSearchSync({ enrollmentIds: [programEnrollment.id] })]+ : []),recordAuditLog({workspaceId: workspace.id,programId,diff --git a/apps/web/scripts/dev/debug-partner-search.ts b/apps/web/scripts/dev/debug-partner-search.tsindex e673072673..9e0ff25ce8 100644--- a/apps/web/scripts/dev/debug-partner-search.ts+++ b/apps/web/scripts/dev/debug-partner-search.ts@@ -146,29 +146,27 @@ const PLATFORM_TYPES = [];/**- * `searchText` is every searchable value lowercased and space-joined in a fixed- * order: partner ID, name, email, company, description, platform types, handles,- * then link keys. Three of those boundaries are recoverable, since the ID is- * prefixed, the email is address-shaped, and the platform types are a known- * enum, so the blob splits into name / profile / platforms-and-keys. A document- * without platforms has no recoverable boundary after the email, so everything- * past it stays together as `profile`.+ * `searchText` joins the searchable values in order: partner ID, tenant ID,+ * name, email, company, description, platform types, handles, link keys. Only+ * the partner ID prefix, the email shape, and the platform enum are+ * recoverable, so the split into identity / profile / platforms-and-keys is a+ * heuristic. The tenant ID has no shape and stays in identity.*/function parseIndexedText(searchText: string) {const tokens = searchText.split(" ").filter(Boolean);const hasPartnerId = tokens[0]?.startsWith("pn_") ?? false;const emailIndex = tokens.findIndex((token) => EMAIL_PATTERN.test(token));- // Without an email there is no boundary after the name, so it is assumed to- // end at the fourth token, and the profile starts where the name ends.- const nameEnd = emailIndex === -1 ? 4 : emailIndex;- const profileStart = emailIndex === -1 ? nameEnd : emailIndex + 1;+ // Without an email there is no boundary after the identity, so it is assumed+ // to end at the fourth token, and the profile starts where the identity ends.+ const identityEnd = emailIndex === -1 ? 4 : emailIndex;+ const profileStart = emailIndex === -1 ? identityEnd : emailIndex + 1;const platformIndex = tokens.findIndex((token, index) => index >= profileStart && PLATFORM_TYPES.includes(token),);return {tokens,- name: tokens.slice(hasPartnerId ? 1 : 0, nameEnd).join(" "),+ identity: tokens.slice(hasPartnerId ? 1 : 0, identityEnd).join(" "),email: emailIndex === -1 ? "" : tokens[emailIndex],profile: tokens.slice(profileStart, platformIndex === -1 ? undefined : platformIndex)@@ -212,7 +210,7 @@ function reportProviderHits(return {rank: index + 1,score: hit.score?.toFixed(5),- name: parsed.name,+ identity: parsed.identity,email: parsed.email,docTokens: parsed.tokens.length,queryTerms: summarizeTermMatches(parsed.tokens, normalizedQuery),