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.

Say what the sync calls do instead of what the sweep cannot

Rafid7f28e0d7ff3
diff --git a/apps/web/app/(ee)/api/admin/partners/delete-account/route.ts b/apps/web/app/(ee)/api/admin/partners/delete-account/route.ts
index e404481c96..6803966dbb 100644
--- a/apps/web/app/(ee)/api/admin/partners/delete-account/route.ts
+++ b/apps/web/app/(ee)/api/admin/partners/delete-account/route.ts
@@ -135,8 +135,7 @@ export const POST = withAdmin(
`Deleted ${partner.programs.length} program enrollments for partner ${partner.email} (${partner.id})`,
);
- // Deletions are invisible to the reconciliation sweep, so without this
- // the documents would survive their enrollments until a full rebuild.
+ // Queue an index update for the deleted enrollments.
await queuePartnerSearchSync({
enrollmentIds: partner.programs.map(({ id }) => id),
});
diff --git a/apps/web/app/(ee)/api/cron/cleanup/declined-invites/route.ts b/apps/web/app/(ee)/api/cron/cleanup/declined-invites/route.ts
index aab64e340e..c57337c149 100644
--- a/apps/web/app/(ee)/api/cron/cleanup/declined-invites/route.ts
+++ b/apps/web/app/(ee)/api/cron/cleanup/declined-invites/route.ts
@@ -53,8 +53,7 @@ export async function POST(req: Request) {
`Deleted ${deletedRes.count} declined programEnrollments that are older than 90 days`,
);
- // Deletions are invisible to the reconciliation sweep, so the index only
- // loses these documents if this hook queues them.
+ // Queue an index update for the deleted enrollments.
await queuePartnerSearchSync({
enrollmentIds: declinedProgramEnrollments.map(({ id }) => id),
});
diff --git a/apps/web/app/(ee)/api/cron/cleanup/rejected-applications/route.ts b/apps/web/app/(ee)/api/cron/cleanup/rejected-applications/route.ts
index 8c68ace83b..075a774c56 100644
--- a/apps/web/app/(ee)/api/cron/cleanup/rejected-applications/route.ts
+++ b/apps/web/app/(ee)/api/cron/cleanup/rejected-applications/route.ts
@@ -60,8 +60,7 @@ export async function POST(req: Request) {
`Deleted ${deletedProgramEnrollments.count} rejected programEnrollments that are older than 30 days`,
);
- // Deletions are invisible to the reconciliation sweep, so the index only
- // loses these documents if this hook queues them.
+ // Queue an index update for the deleted enrollments.
await queuePartnerSearchSync({
enrollmentIds: rejectedProgramEnrollments.map(({ id }) => id),
});
diff --git a/apps/web/app/(ee)/api/cron/partners/delete/route.ts b/apps/web/app/(ee)/api/cron/partners/delete/route.ts
index 86a8ba5e13..3574dc8679 100644
--- a/apps/web/app/(ee)/api/cron/partners/delete/route.ts
+++ b/apps/web/app/(ee)/api/cron/partners/delete/route.ts
@@ -158,9 +158,7 @@ export const POST = withCron(async ({ rawBody }) => {
}),
]);
- // Queued after the enrollment is gone, so the job reads nothing back and
- // removes the document. No sweep can do this: a pass only sees rows that
- // still exist.
+ // Queue an index update for the deleted enrollment.
await queuePartnerSearchSync({ enrollmentIds: [enrollment.id] });
await recordAuditLog({
diff --git a/apps/web/lib/actions/partners/delete-program-invite.ts b/apps/web/lib/actions/partners/delete-program-invite.ts
index 08aa9aa24b..ebc1545f7f 100644
--- a/apps/web/lib/actions/partners/delete-program-invite.ts
+++ b/apps/web/lib/actions/partners/delete-program-invite.ts
@@ -117,8 +117,7 @@ export const deleteProgramInviteAction = authActionClient
],
}),
- // Deletions are invisible to the reconciliation sweep, so this hook is
- // the only thing that clears the document.
+ // Queue an index update for the deleted enrollment.
queuePartnerSearchSync({ enrollmentIds: [programEnrollment.id] }),
]),
);
diff --git a/apps/web/lib/actions/partners/tags/update-program-partner-tags.ts b/apps/web/lib/actions/partners/tags/update-program-partner-tags.ts
index 771cf06c7c..3b7cd34cf7 100644
--- a/apps/web/lib/actions/partners/tags/update-program-partner-tags.ts
+++ b/apps/web/lib/actions/partners/tags/update-program-partner-tags.ts
@@ -95,9 +95,7 @@ export const updateProgramPartnerTagsAction = authActionClient
]);
});
- // Tags carry no timestamps, so the reconciliation sweep cannot notice this
- // change on its own. This hook is the only thing keeping tag filters in the
- // index honest between full rebuilds.
+ // Queue an index update for the changed tags.
waitUntil(queuePartnerSearchSync({ partnerIds, programId }));
// Sync updated partner tags to Tinybird for analytics (top_partner_tags)
diff --git a/apps/web/lib/actions/partners/withdraw-partner-application.ts b/apps/web/lib/actions/partners/withdraw-partner-application.ts
index d7f78641cd..b9da2f13f0 100644
--- a/apps/web/lib/actions/partners/withdraw-partner-application.ts
+++ b/apps/web/lib/actions/partners/withdraw-partner-application.ts
@@ -49,7 +49,7 @@ export const withdrawPartnerApplicationAction = authPartnerActionClient
return deletedProgramEnrollment;
});
- // A withdrawal deletes the enrollment, which no sweep can notice.
+ // Queue an index update for the deleted enrollment.
waitUntil(
queuePartnerSearchSync({ enrollmentIds: [programEnrollment.id] }),
);
diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.ts
index e5893f3428..3048dc02b7 100644
--- a/apps/web/lib/api/links/bulk-update-links.ts
+++ b/apps/web/lib/api/links/bulk-update-links.ts
@@ -130,8 +130,7 @@ export async function bulkUpdateLinks(
propagateBulkLinkChanges({
links: updatedLinks,
}),
- // A bulk edit can move the destination URL, and the key or domain behind
- // the short link.
+ // A bulk edit can change the destination URL or the link owner.
queuePartnerSearchSyncForLinks([...previousOwners, ...updatedLinks], {
delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
}),
diff --git a/apps/web/lib/api/partners/bulk-delete-partners.ts b/apps/web/lib/api/partners/bulk-delete-partners.ts
index cdd26bf549..bebd7f1523 100644
--- a/apps/web/lib/api/partners/bulk-delete-partners.ts
+++ b/apps/web/lib/api/partners/bulk-delete-partners.ts
@@ -161,9 +161,7 @@ export async function bulkDeletePartners({
`Deleted ${deletedProgramEnrollments.count} program enrollments`,
);
- // Deletions are invisible to the reconciliation sweep, which only sees rows
- // that still exist. The job removes what it cannot read back, so passing
- // the now-gone IDs is what clears them from the index.
+ // Queue an index update for the deleted enrollments.
await queuePartnerSearchSync({ enrollmentIds: programEnrollmentIds });
if (deletedProgramEnrollments.count > 0) {
diff --git a/apps/web/lib/api/partners/queue-partner-search-sync.ts b/apps/web/lib/api/partners/queue-partner-search-sync.ts
index bf71cdd48c..c5c263078d 100644
--- a/apps/web/lib/api/partners/queue-partner-search-sync.ts
+++ b/apps/web/lib/api/partners/queue-partner-search-sync.ts
@@ -50,12 +50,8 @@ function unique(values: string[] | undefined): string[] {
/**
* Queues an index sync for whatever the caller just changed.
*
- * Never throws. A search index that falls behind costs relevance ranking and
- * the wider field coverage, which the read path already degrades to when no
- * provider is configured. A partner mutation failing because a queue was
- * unreachable would be a far worse outcome. Job dispatch already persists to
- * the database when QStash is unavailable, so reaching the catch here means
- * both paths failed, and the reconciliation sweep is what recovers from it.
+ * Never throws, so a queue error cannot fail the source mutation. The sweep
+ * repairs a missed upsert, but not a missed delete.
*/
export async function queuePartnerSearchSync({
enrollmentIds,
@@ -92,7 +88,7 @@ export async function queuePartnerSearchSync({
await partnerSearchSyncJob.dispatchBatch(payloads, () => ({ delay }));
} catch (error) {
console.error(
- "[Partner Search] Failed to queue an index sync. The reconciliation sweep will pick this up.",
+ "[Partner Search] Failed to queue an index sync. The sweep repairs a missed upsert, but not a missed delete.",
error,
);
}
diff --git a/apps/web/lib/api/partners/search/sweep.ts b/apps/web/lib/api/partners/search/sweep.ts
index e8fe1e55cf..8f50a5f5c2 100644
--- a/apps/web/lib/api/partners/search/sweep.ts
+++ b/apps/web/lib/api/partners/search/sweep.ts
@@ -26,10 +26,10 @@ interface SweepPartnerSearchOptions {
* next pass.
*
* Re-indexes everything rather than filtering by timestamp, because a watermark
- * cannot see a tag change (ProgramPartnerTag has no timestamps) or a link edit
- * (which moves neither the enrollment's nor the partner's).
+ * misses a tag change (ProgramPartnerTag has no timestamps) and a link edit
+ * (which moves neither the enrollment's timestamp nor the partner's).
*
- * Deletions stay outside this. A pass only sees rows that still exist.
+ * Upserts only: a pass re-indexes the rows it reads.
*/
export async function sweepPartnerSearch({
after,
diff --git a/apps/web/lib/jobs/handlers/partner-tag-deleted-job.ts b/apps/web/lib/jobs/handlers/partner-tag-deleted-job.ts
index 48c3e17083..f6aba9d159 100644
--- a/apps/web/lib/jobs/handlers/partner-tag-deleted-job.ts
+++ b/apps/web/lib/jobs/handlers/partner-tag-deleted-job.ts
@@ -70,7 +70,7 @@ export const partnerTagDeletedJob = defineJob({
`[partnerTagDeletedJob] Deleted ${count} program–partner tag associations.`,
);
- // Tags carry no timestamps, so the reconciliation sweep cannot see this.
+ // Queue an index update for the affected enrollments.
await queuePartnerSearchSync({
enrollmentIds: programPartnerTags.map(
({ programEnrollment }) => programEnrollment.id,
diff --git a/apps/web/lib/tapfiliate/cleanup-partners.ts b/apps/web/lib/tapfiliate/cleanup-partners.ts
index cf2607f337..883362502d 100644
--- a/apps/web/lib/tapfiliate/cleanup-partners.ts
+++ b/apps/web/lib/tapfiliate/cleanup-partners.ts
@@ -58,9 +58,8 @@ export async function cleanupPartners(payload: TapfiliateImportPayload) {
await bulkDeleteLinks(linksToDelete);
- // Resolved before the delete, because afterwards nothing can map these
- // partners back to the enrollments they had, and a deletion is invisible
- // to the reconciliation sweep.
+ // Resolved before the delete, since nothing can map these partners back
+ // to their enrollments afterwards.
const removedEnrollments = await prisma.programEnrollment.findMany({
where: {
programId,
diff --git a/apps/web/lib/tolt/cleanup-partners.ts b/apps/web/lib/tolt/cleanup-partners.ts
index 103f3ec1ab..9ababf2315 100644
--- a/apps/web/lib/tolt/cleanup-partners.ts
+++ b/apps/web/lib/tolt/cleanup-partners.ts
@@ -52,9 +52,8 @@ export async function cleanupPartners({ programId }: { programId: string }) {
await bulkDeleteLinks(linksToDelete);
- // Resolved before the delete, because afterwards nothing can map these
- // partners back to the enrollments they had, and a deletion is invisible
- // to the reconciliation sweep.
+ // Resolved before the delete, since nothing can map these partners back
+ // to their enrollments afterwards.
const removedEnrollments = await prisma.programEnrollment.findMany({
where: {
programId,