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.

Drop the link sync delay

Rafifaed12507426
diff --git a/apps/web/app/(ee)/api/cron/domains/update/route.ts b/apps/web/app/(ee)/api/cron/domains/update/route.ts
index 789761f1d0..49572272c9 100644
--- a/apps/web/app/(ee)/api/cron/domains/update/route.ts
+++ b/apps/web/app/(ee)/api/cron/domains/update/route.ts
@@ -6,10 +6,7 @@ import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { linkCache } from "@/lib/api/links/cache";
import { includeProgramEnrollment } from "@/lib/api/links/include-program-enrollment";
import { includeTags } from "@/lib/api/links/include-tags";
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSyncForLinks,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSyncForLinks } from "@/lib/api/partners/queue-partner-search-sync";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
import { prisma } from "@/lib/prisma";
import { recordLink } from "@/lib/tinybird";
@@ -108,9 +105,7 @@ export async function POST(req: Request) {
// Queue an index update because the domain change rewrote each link's
// shortLink. Queued after updateShortLinks above, which performs the
// rewrite.
- await queuePartnerSearchSyncForLinks(updatedLinks, {
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- });
+ await queuePartnerSearchSyncForLinks(updatedLinks);
const response = await queueDomainUpdate({
...payload,
diff --git a/apps/web/app/(ee)/api/cron/groups/sync-utm/route.ts b/apps/web/app/(ee)/api/cron/groups/sync-utm/route.ts
index 873c6db890..a021991a84 100644
--- a/apps/web/app/(ee)/api/cron/groups/sync-utm/route.ts
+++ b/apps/web/app/(ee)/api/cron/groups/sync-utm/route.ts
@@ -1,9 +1,6 @@
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { linkCache } from "@/lib/api/links/cache";
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSync,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
import { extractUtmParams } from "@/lib/api/utm/extract-utm-params";
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
@@ -134,7 +131,6 @@ export async function POST(req: Request) {
// destination URL.
await queuePartnerSearchSync({
enrollmentIds: programEnrollments.map(({ id }) => id),
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
});
if (programEnrollments.length === PAGE_SIZE) {
diff --git a/apps/web/app/(ee)/api/cron/groups/update-default-links/route.ts b/apps/web/app/(ee)/api/cron/groups/update-default-links/route.ts
index c521d83a6d..470c53d236 100644
--- a/apps/web/app/(ee)/api/cron/groups/update-default-links/route.ts
+++ b/apps/web/app/(ee)/api/cron/groups/update-default-links/route.ts
@@ -1,9 +1,6 @@
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { linkCache } from "@/lib/api/links/cache";
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSyncForLinks,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSyncForLinks } from "@/lib/api/partners/queue-partner-search-sync";
import { extractUtmParams } from "@/lib/api/utm/extract-utm-params";
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
@@ -206,7 +203,6 @@ export async function POST(req: Request) {
// destination URLs.
await queuePartnerSearchSyncForLinks(
linksToUpdate.map(({ owner }) => owner),
- { delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS },
);
}
diff --git a/apps/web/lib/api/links/bulk-delete-links.ts b/apps/web/lib/api/links/bulk-delete-links.ts
index 156de0dd1c..0beb96dac5 100644
--- a/apps/web/lib/api/links/bulk-delete-links.ts
+++ b/apps/web/lib/api/links/bulk-delete-links.ts
@@ -1,7 +1,4 @@
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSyncForLinks,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSyncForLinks } from "@/lib/api/partners/queue-partner-search-sync";
import { deleteDiscountCodes } from "@/lib/discounts/delete-discount-code";
import { prisma } from "@/lib/prisma";
import { storage } from "@/lib/storage";
@@ -68,7 +65,6 @@ export async function bulkDeleteLinks(
// Queue an index update because the links were deleted. The enrollment
// outlives them, so the document is re-serialized without them.
queuePartnerSearchSyncForLinks(links, {
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
}),
]),
);
diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.ts
index 856c03b7a8..5f5f052c60 100644
--- a/apps/web/lib/api/links/bulk-update-links.ts
+++ b/apps/web/lib/api/links/bulk-update-links.ts
@@ -1,7 +1,4 @@
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSyncForLinks,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSyncForLinks } from "@/lib/api/partners/queue-partner-search-sync";
import { prisma } from "@/lib/prisma";
import { isNotHostedImage, storage } from "@/lib/storage";
import { bulkUpdateLinksBodySchema } from "@/lib/zod/schemas/links";
@@ -132,9 +129,7 @@ export async function bulkUpdateLinks(
}),
// Queue an index update because a bulk edit can change the destination
// URL or the link owner.
- queuePartnerSearchSyncForLinks([...previousOwners, ...updatedLinks], {
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- }),
+ queuePartnerSearchSyncForLinks([...previousOwners, ...updatedLinks]),
// if proxy is true and image is not stored in R2, upload image to R2
proxy &&
image &&
diff --git a/apps/web/lib/api/links/complete-ab-tests.ts b/apps/web/lib/api/links/complete-ab-tests.ts
index bfb5f76cdd..c114b592b0 100644
--- a/apps/web/lib/api/links/complete-ab-tests.ts
+++ b/apps/web/lib/api/links/complete-ab-tests.ts
@@ -1,8 +1,5 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSyncForLinks,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSyncForLinks } from "@/lib/api/partners/queue-partner-search-sync";
import { prisma } from "@/lib/prisma";
import { recordLink } from "@/lib/tinybird";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
@@ -84,9 +81,7 @@ export async function completeABTests(link: Link) {
recordLink(response),
// Queue an index update because the winning variant replaced the
// destination URL.
- queuePartnerSearchSyncForLinks([response], {
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- }),
+ queuePartnerSearchSyncForLinks([response]),
// send a link.updated webhook to the workspace
response.project &&
sendWorkspaceWebhook({
diff --git a/apps/web/lib/api/links/delete-link.ts b/apps/web/lib/api/links/delete-link.ts
index 791767c8af..dad9719fd9 100644
--- a/apps/web/lib/api/links/delete-link.ts
+++ b/apps/web/lib/api/links/delete-link.ts
@@ -1,7 +1,4 @@
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSync,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
import { deleteDiscountCodes } from "@/lib/discounts/delete-discount-code";
import { prisma } from "@/lib/prisma";
import { storage } from "@/lib/storage";
@@ -71,7 +68,6 @@ export async function deleteLink(linkId: string) {
queuePartnerSearchSync({
partnerIds: [link.partnerId],
programId: link.programId,
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
}),
]),
);
diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.ts
index 64ef380906..92a94cf898 100644
--- a/apps/web/lib/api/links/update-link.ts
+++ b/apps/web/lib/api/links/update-link.ts
@@ -1,7 +1,4 @@
-import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
- queuePartnerSearchSyncForLinks,
-} from "@/lib/api/partners/queue-partner-search-sync";
+import { queuePartnerSearchSyncForLinks } from "@/lib/api/partners/queue-partner-search-sync";
import { getPartnerEnrollmentInfo } from "@/lib/planetscale/get-partner-enrollment-info";
import { prisma } from "@/lib/prisma";
import { isNotHostedImage, storage } from "@/lib/storage";
@@ -215,7 +212,6 @@ export async function updateLink({
// or move the link. Both owners, so a former one is re-serialized
// without it.
queuePartnerSearchSyncForLinks([oldLink, response], {
- delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
}),
// If proxy is true and image is not stored in R2, upload image to R2
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 c5c263078d..6488498c31 100644
--- a/apps/web/lib/api/partners/queue-partner-search-sync.ts
+++ b/apps/web/lib/api/partners/queue-partner-search-sync.ts
@@ -15,15 +15,6 @@ import {
*/
export const PARTNER_SEARCH_SYNC_DELAY_SECONDS = 5;
-/**
- * Link edits are frequent and only move `shortLinks` and `destinationUrls`, so
- * their syncs are spread out. Creation uses the default delay, since a new
- * short link is how people search for that partner.
- *
- * Worth revisiting: this stopped reducing writes when deduplication was removed.
- */
-export const PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS = 300;
-
type PartnerSearchSyncPayload =
| { type: "enrollments"; enrollmentIds: string[] }
| { type: "partners"; partnerIds: string[]; programId?: string };
diff --git a/apps/web/lib/jobs/handlers/partner-search-sync-job.ts b/apps/web/lib/jobs/handlers/partner-search-sync-job.ts
index 1da988e098..998176bd38 100644
--- a/apps/web/lib/jobs/handlers/partner-search-sync-job.ts
+++ b/apps/web/lib/jobs/handlers/partner-search-sync-job.ts
@@ -85,8 +85,6 @@ export const partnerSearchSyncJob = defineJob({
return;
}
- // These IDs came from the database a moment ago, so this upserts rather
- // than deletes, unless one vanished in between, which is also correct.
const { upserted, deleted } = await syncPartnerSearchDocuments({
enrollmentIds,
searchProvider,
@@ -96,7 +94,6 @@ export const partnerSearchSyncJob = defineJob({
`[partnerSearchSyncJob] Synced ${upserted} and removed ${deleted} enrollment documents for ${input.partnerIds.length} partner(s).`,
);
- // A full page means there may be more enrollments for these partners.
if (enrollmentIds.length === PARTNER_SEARCH_SYNC_BATCH_SIZE) {
await partnerSearchSyncJob.dispatch(
{
diff --git a/apps/web/tests/partners/queue-partner-search-sync.test.ts b/apps/web/tests/partners/queue-partner-search-sync.test.ts
index 89fe23b162..62e9a628c7 100644
--- a/apps/web/tests/partners/queue-partner-search-sync.test.ts
+++ b/apps/web/tests/partners/queue-partner-search-sync.test.ts
@@ -1,5 +1,4 @@
import {
- PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
PARTNER_SEARCH_SYNC_DELAY_SECONDS,
queuePartnerSearchSync,
queuePartnerSearchSyncForLinks,
@@ -177,17 +176,17 @@ describe("queuePartnerSearchSyncForLinks", () => {
]);
});
- it("passes the delay through so link edits can batch harder than creations", async () => {
+ it("passes an explicit delay through", async () => {
await queuePartnerSearchSyncForLinks(
[{ programId: "prog_1", partnerId: "pn_1" }],
- { delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS },
+ { delay: 60 },
);
const [, getOptions] = mocks.dispatchBatch.mock.calls[0];
expect(
getOptions({ type: "partners", partnerIds: ["pn_1"] }, 0).delay,
- ).toBe(PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS);
+ ).toBe(60);
});
it("defaults to the interactive delay when none is given", async () => {