The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Queue the search sync before unrelated external work
Rafi8ec224909e3a
diff --git a/apps/web/scripts/customers/buffer/migrate-to-case-sensitive.ts b/apps/web/scripts/customers/buffer/migrate-to-case-sensitive.tsindex 05de1a2795..5c5c1572bb 100644--- a/apps/web/scripts/customers/buffer/migrate-to-case-sensitive.ts+++ b/apps/web/scripts/customers/buffer/migrate-to-case-sensitive.ts@@ -94,11 +94,12 @@ async function main() {});}+ // Queue an index update for the owners of the links that changed key, ahead+ // of the cache expiry below.+ await queuePartnerSearchSyncForLinks(links);+// expire the Redis cache for the links so it fetches the latest version from the databaseawait linkCache.expireMany(links);-- // Queue an index update for the owners of the links that changed key.- await queuePartnerSearchSyncForLinks(links);}main();diff --git a/apps/web/scripts/misc/restore-program-enrollments.ts b/apps/web/scripts/misc/restore-program-enrollments.tsindex f51d7fd4d3..6a6de03d44 100644--- a/apps/web/scripts/misc/restore-program-enrollments.ts+++ b/apps/web/scripts/misc/restore-program-enrollments.ts@@ -47,6 +47,13 @@ async function main() {});console.log(`Restored ${res.count} program enrollments`);+ // Queued after the last write the document reads, and before the Tinybird and+ // Stripe work, which must not be able to skip it.+ const queueSearchSync = () =>+ queuePartnerSearchSync({+ enrollmentIds: programEnrollmentsToRestore.map(({ id }) => id),+ });+// Restore payouts first (commissions may reference payoutId)const payoutsToRestore = await prismaOld.payout.findMany({where: { partnerId },@@ -128,6 +135,8 @@ async function main() {});console.log(`Restored ${createdLinkTagsCount} link tags`);+ await queueSearchSync();+const restoredLinks = await prisma.link.findMany({where: { partnerId },include: {@@ -151,6 +160,8 @@ async function main() {);console.log(`Restored ${createdCustomersCount} customers`);}+ } else {+ await queueSearchSync();}const discountCodesToRestore = await prismaOld.discountCode.findMany({@@ -212,11 +223,6 @@ async function main() {console.log(`Restored promotion code ${JSON.stringify(res, null, 2)}`);}}-- // Queue an index update for the restored enrollments.- await queuePartnerSearchSync({- enrollmentIds: programEnrollmentsToRestore.map(({ id }) => id),- });}main();diff --git a/apps/web/scripts/partners/merge-partner-profile.ts b/apps/web/scripts/partners/merge-partner-profile.tsindex dae35b6ed3..11ad0680c5 100644--- a/apps/web/scripts/partners/merge-partner-profile.ts+++ b/apps/web/scripts/partners/merge-partner-profile.ts@@ -61,6 +61,10 @@ async function main() {},});+ // Queue an index update for the reassigned enrollment, ahead of the+ // Tinybird write below.+ await queuePartnerSearchSync({ enrollmentIds: [programEnrollment.id] });+const updatedLinks = await prisma.link.findMany({where: {programId,@@ -76,9 +80,6 @@ async function main() {const tbRes = await recordLink(updatedLinks);console.log("tbRes", tbRes);-- // Queue an index update for the reassigned enrollment.- await queuePartnerSearchSync({ enrollmentIds: [programEnrollment.id] });}main();diff --git a/apps/web/scripts/partners/update-links.ts b/apps/web/scripts/partners/update-links.tsindex 58a6e1dd2c..07c08ae98f 100644--- a/apps/web/scripts/partners/update-links.ts+++ b/apps/web/scripts/partners/update-links.ts@@ -34,16 +34,6 @@ async function main() {console.log(updatedLinks);- const res = await Promise.all([- linkCache.expireMany(links),- recordLink(- links.map((link) => ({- ...link,- domain: newDomain,- })),- ),- ]);-await Promise.all(links.map(async (link) => {return await prisma.link.update({@@ -57,11 +47,22 @@ async function main() {}),);- console.log(res);-- // Queue an index update for the links that changed domain. The helper only- // reads programId and partnerId, which the move does not touch.+ // Queue an index update for the links that changed domain, ahead of the cache+ // and Tinybird work below. The helper only reads programId and partnerId,+ // which the move does not touch.await queuePartnerSearchSyncForLinks(links);++ const res = await Promise.all([+ linkCache.expireMany(links),+ recordLink(+ links.map((link) => ({+ ...link,+ domain: newDomain,+ })),+ ),+ ]);++ console.log(res);}main();