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.

Clear the index when a partner is permanently deleted

Rafife8379921c08
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 1d9f29f5be..e404481c96 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
@@ -1,4 +1,5 @@
import { bulkDeleteLinks } from "@/lib/api/links/bulk-delete-links";
+import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
import { withAdmin } from "@/lib/auth";
import { conn } from "@/lib/planetscale";
import { prisma } from "@/lib/prisma";
@@ -19,6 +20,9 @@ export const POST = withAdmin(
commissions: true,
programs: {
select: {
+ // Needed to clear these enrollments from the search index once they
+ // are gone, since nothing can resolve their IDs afterwards.
+ id: true,
program: true,
links: true,
groupId: true,
@@ -130,6 +134,12 @@ export const POST = withAdmin(
console.log(
`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.
+ await queuePartnerSearchSync({
+ enrollmentIds: partner.programs.map(({ id }) => id),
+ });
}
await conn.execute(`DELETE FROM Partner WHERE id = ?`, [partner.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 32155f84c8..627a34ca78 100644
--- a/apps/web/app/(ee)/api/cron/partners/delete/route.ts
+++ b/apps/web/app/(ee)/api/cron/partners/delete/route.ts
@@ -1,6 +1,7 @@
import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { bulkDeleteLinks } from "@/lib/api/links/bulk-delete-links";
import { includeTags } from "@/lib/api/links/include-tags";
+import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
import { withCron } from "@/lib/cron/with-cron";
import { aggregatePartnerLinksStats } from "@/lib/partners/aggregate-partner-links-stats";
import { canDeletePartner } from "@/lib/partners/utils";
@@ -157,6 +158,11 @@ export const POST = withCron(async ({ rawBody }) => {
}),
]);
+ // Queued after the enrollment is gone, so the job reads nothing back and
+ // removes the document. The sweep can never do this for us: a pass only sees
+ // rows that still exist, so an orphaned document is invisible to it.
+ await queuePartnerSearchSync({ enrollmentIds: [enrollment.id] });
+
await recordAuditLog({
workspaceId,
programId,