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.

Close three more search sync gaps

Rafi90b703694c27
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 c49ee264f4..5dc5c2915e 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,5 +1,9 @@
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 { extractUtmParams } from "@/lib/api/utm/extract-utm-params";
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
@@ -121,6 +125,9 @@ export async function POST(req: Request) {
url: true,
domain: true,
key: true,
+ // Needed to re-index the owners after the URL changes below.
+ programId: true,
+ partnerId: true,
partner: {
select: {
name: true,
@@ -136,6 +143,7 @@ export async function POST(req: Request) {
const linksToUpdate: {
id: string;
+ owner: { programId: string | null; partnerId: string | null };
link: Pick<
Link,
| "url"
@@ -171,6 +179,10 @@ export async function POST(req: Request) {
linksToUpdate.push({
id: defaultPartnerLink.id,
+ owner: {
+ programId: defaultPartnerLink.programId,
+ partnerId: defaultPartnerLink.partnerId,
+ },
link: {
url,
...extractUtmParams(group.utmTemplate, { excludeRef: true }),
@@ -189,6 +201,13 @@ export async function POST(req: Request) {
}),
),
);
+
+ // The destination URL is searchable, so the owners of the links that
+ // actually changed have to be re-indexed.
+ await queuePartnerSearchSyncForLinks(
+ linksToUpdate.map(({ owner }) => owner),
+ { delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS },
+ );
}
console.log(
diff --git a/apps/web/app/(ee)/api/cron/partner-platforms/youtube/route.ts b/apps/web/app/(ee)/api/cron/partner-platforms/youtube/route.ts
index 523e7c4fec..1d13cdd5d7 100644
--- a/apps/web/app/(ee)/api/cron/partner-platforms/youtube/route.ts
+++ b/apps/web/app/(ee)/api/cron/partner-platforms/youtube/route.ts
@@ -1,3 +1,4 @@
+import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
import { qstash } from "@/lib/cron";
import { withCron } from "@/lib/cron/with-cron";
import { prisma } from "@/lib/prisma";
@@ -99,13 +100,18 @@ export const POST = withCron(async ({ rawBody }) => {
}),
};
+ // Broken out because it is the only change here the search index
+ // cares about. The rest are stats, which the document does not carry.
+ const identifierChanged =
+ "identifier" in newStats &&
+ partnerPlatform.identifier !== newStats.identifier;
+
const hasChanges =
partnerPlatform.subscribers !== BigInt(newStats.subscribers) ||
partnerPlatform.posts !== BigInt(newStats.posts) ||
partnerPlatform.views !== BigInt(newStats.views) ||
partnerPlatform.avatarUrl !== newStats.avatarUrl ||
- ("identifier" in newStats &&
- partnerPlatform.identifier !== newStats.identifier);
+ identifierChanged;
if (!hasChanges) {
console.log(
@@ -124,6 +130,12 @@ export const POST = withCron(async ({ rawBody }) => {
},
});
+ if (identifierChanged) {
+ await queuePartnerSearchSync({
+ partnerIds: [partnerPlatform.partnerId],
+ });
+ }
+
console.log(
`Updated YouTube stats for @${partnerPlatform.identifier}`,
newStats,
diff --git a/apps/web/lib/api/links/complete-ab-tests.ts b/apps/web/lib/api/links/complete-ab-tests.ts
index 7175441e9b..7e3bb6be7d 100644
--- a/apps/web/lib/api/links/complete-ab-tests.ts
+++ b/apps/web/lib/api/links/complete-ab-tests.ts
@@ -1,4 +1,8 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
+import {
+ PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
+ 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";
@@ -78,6 +82,10 @@ export async function completeABTests(link: Link) {
linkCache.set(response),
// record the link
recordLink(response),
+ // The winning variant replaces the destination URL, which is searchable.
+ queuePartnerSearchSyncForLinks([response], {
+ delay: PARTNER_SEARCH_LINK_SYNC_DELAY_SECONDS,
+ }),
// send a link.updated webhook to the workspace
response.project &&
sendWorkspaceWebhook({