The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
wip
Kiran K7dab69edd58b
diff --git a/apps/web/app/(ee)/api/cron/discounts/enqueue-coupon-code-delete-jobs/route.ts b/apps/web/app/(ee)/api/cron/discounts/queue-coupon-code-delete-jobs/route.tssimilarity index 100%rename from apps/web/app/(ee)/api/cron/discounts/enqueue-coupon-code-delete-jobs/route.tsrename to apps/web/app/(ee)/api/cron/discounts/queue-coupon-code-delete-jobs/route.tsdiff --git a/apps/web/lib/actions/partners/update-discount.ts b/apps/web/lib/actions/partners/update-discount.tsindex 373b6d3070..fc61acbf9b 100644--- a/apps/web/lib/actions/partners/update-discount.ts+++ b/apps/web/lib/actions/partners/update-discount.ts@@ -25,10 +25,8 @@ export const updateDiscountAction = authActionClient});const couponCodeTrackingEnabledAt = enableCouponTracking- ? discount.couponCodeTrackingEnabledAt ?? new Date() // enable once- : discount.couponCodeTrackingEnabledAt- ? null // disable- : null; // already disabled, keep null+ ? discount.couponCodeTrackingEnabledAt ?? new Date()+ : null;const { partnerGroup, ...updatedDiscount } = await prisma.discount.update({where: {@@ -47,8 +45,10 @@ export const updateDiscountAction = authActionClient},});- const { couponTestIdChanged, trackingEnabled, trackingDisabled } =- detectDiscountChanges(discount, updatedDiscount);+ const { couponTestIdChanged, trackingDisabled } = detectDiscountChanges(+ discount,+ updatedDiscount,+ );waitUntil(Promise.allSettled([@@ -108,3 +108,50 @@ function detectDiscountChanges(trackingDisabled,};}++async function queueDiscountCodeDeletionJobs(discountId: string) {+ const queue = qstash.queue({+ queueName: "discount-code-deletion",+ });++ await queue.upsert({+ parallelism: 10,+ });++ // take 100 and do pagination++ const pageSize = 100+ let hasMore = true+ let cursor = null++ while (hasMore) {+ const discountCode = await prisma.discountCode.findMany({+ where: {+ discountId,+ },+ select: {+ id: true,+ },+ take: pageSize,+ orderBy: {+ createdAt: "asc",+ },+ ...(cursor ? {+ cursor: {+ id: cursor,+ },+ }),+ });+ }+++++ // const response = await queue.enqueueJSON({+ // url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discounts/delete-discount-code`,+ // method: "POST",+ // body: {+ // discountCodeId =+ // },+ // });+}