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.

revert the changes

Kiran K02256b697521
diff --git a/apps/web/lib/api/links/bulk-create-links.ts b/apps/web/lib/api/links/bulk-create-links.ts
index 97453f0690..48b898db23 100644
--- a/apps/web/lib/api/links/bulk-create-links.ts
+++ b/apps/web/lib/api/links/bulk-create-links.ts
@@ -213,43 +213,16 @@ export async function bulkCreateLinks({
}
waitUntil(
- (async () => {
- // Find the links with coupon code tracking enabled
- const partnerLinks = await prisma.link.findMany({
- where: {
- id: {
- in: createdLinksData.map((link) => link.id),
- },
- },
- select: {
- id: true,
- key: true,
- programEnrollment: {
- select: {
- discount: {
- where: {
- couponCodeTrackingEnabledAt: {
- not: null,
- },
- },
- },
- },
- },
- },
- });
-
- await Promise.allSettled([
- propagateBulkLinkChanges({
- links: createdLinksData,
- skipRedisCache,
- }),
-
- updateLinksUsage({
- workspaceId: links[0].projectId!, // this will always be present
- increment: links.length,
- }),
- ]);
- })(),
+ Promise.all([
+ propagateBulkLinkChanges({
+ links: createdLinksData,
+ skipRedisCache,
+ }),
+ updateLinksUsage({
+ workspaceId: links[0].projectId!, // this will always be present
+ increment: links.length,
+ }),
+ ]),
);
// Simplified sorting using the map
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index 72d5b70234..fad95d5736 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -139,71 +139,63 @@ export async function createLink(link: ProcessedLinkProps) {
const uploadedImageUrl = `${R2_URL}/images/${response.id}`;
waitUntil(
- (async () => {
- const partnerAndDiscount = await getPartnerAndDiscount({
- programId: response.programId,
- partnerId: response.partnerId,
- });
-
- await Promise.allSettled([
- // cache link in Redis
- linkCache.set({
- ...response,
- ...(partnerAndDiscount && {
- ...partnerAndDiscount,
- }),
+ Promise.allSettled([
+ // cache link in Redis
+ linkCache.set({
+ ...response,
+ ...(response.programId &&
+ (await getPartnerAndDiscount({
+ programId: response.programId,
+ partnerId: response.partnerId,
+ }))),
+ }),
+
+ // record link in Tinybird
+ recordLink(response),
+ // Upload image to R2 and update the link with the uploaded image URL when
+ // proxy is enabled and image is set and is not a hosted image URL
+ ...(proxy && image && isNotHostedImage(image)
+ ? [
+ // upload image to R2
+ storage.upload(`images/${response.id}`, image, {
+ width: 1200,
+ height: 630,
+ }),
+ // update the null image we set earlier to the uploaded image URL
+ prisma.link.update({
+ where: {
+ id: response.id,
+ },
+ data: {
+ image: uploadedImageUrl,
+ },
+ }),
+ ]
+ : []),
+ // delete public links after 30 mins
+ !response.userId &&
+ qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/delete`,
+ // delete after 30 mins
+ delay: 30 * 60,
+ body: {
+ linkId: response.id,
+ },
+ }),
+ // update links usage for workspace
+ link.projectId &&
+ updateLinksUsage({
+ workspaceId: link.projectId,
+ increment: 1,
}),
- // record link in Tinybird
- recordLink(response),
-
- // Upload image to R2 and update the link with the uploaded image URL when
- // proxy is enabled and image is set and is not a hosted image URL
- ...(proxy && image && isNotHostedImage(image)
- ? [
- // upload image to R2
- storage.upload(`images/${response.id}`, image, {
- width: 1200,
- height: 630,
- }),
- // update the null image we set earlier to the uploaded image URL
- prisma.link.update({
- where: {
- id: response.id,
- },
- data: {
- image: uploadedImageUrl,
- },
- }),
- ]
- : []),
-
- // delete public links after 30 mins
- !response.userId &&
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/delete`,
- // delete after 30 mins
- delay: 30 * 60,
- body: {
- linkId: response.id,
- },
- }),
-
- // update links usage for workspace
- link.projectId &&
- updateLinksUsage({
- workspaceId: link.projectId,
- increment: 1,
- }),
-
- webhookIds &&
- propagateWebhookTriggerChanges({
- webhookIds,
- }),
+ webhookIds &&
+ propagateWebhookTriggerChanges({
+ webhookIds,
+ }),
- testVariants && testCompletedAt && scheduleABTestCompletion(response),
- ]);
- })(),
+ testVariants && testCompletedAt && scheduleABTestCompletion(response),
+ ]),
);
return {