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.

Fix domain cron link clicks check

Steven Tey897810a12c73
diff --git a/apps/web/app/api/cron/domains/verify/route.ts b/apps/web/app/api/cron/domains/verify/route.ts
index b5e9e293ee..63f363844b 100644
--- a/apps/web/app/api/cron/domains/verify/route.ts
+++ b/apps/web/app/api/cron/domains/verify/route.ts
@@ -114,8 +114,6 @@ export async function GET(req: Request) {
verified: newVerified,
primary,
changed,
- clicks: domain.clicks,
- linksCount: _count.links - 1 || 0,
});
return {
diff --git a/apps/web/app/api/cron/domains/verify/utils.ts b/apps/web/app/api/cron/domains/verify/utils.ts
index b4881acd95..6e23cbae0c 100644
--- a/apps/web/app/api/cron/domains/verify/utils.ts
+++ b/apps/web/app/api/cron/domains/verify/utils.ts
@@ -12,16 +12,12 @@ export const handleDomainUpdates = async ({
verified,
primary,
changed,
- clicks,
- linksCount,
}: {
domain: string;
createdAt: Date;
verified: boolean;
primary: boolean;
changed: boolean;
- clicks: number;
- linksCount: number;
}) => {
if (changed) {
await log({
@@ -80,28 +76,20 @@ export const handleDomainUpdates = async ({
// if domain is invalid for more than 30 days, check if we can delete it
if (invalidDays >= 30) {
// Don't delete the domain (manual inspection required) if:
- // - the domain has clicks
// - there are still links associated with the domain and those links have clicks
- if (clicks > 0) {
+ const linksClicks = await prisma.link.aggregate({
+ _sum: {
+ clicks: true,
+ },
+ where: {
+ domain,
+ },
+ });
+ if (linksClicks._sum?.clicks) {
return await log({
- message: `Domain *${domain}* has been invalid for > 30 days but has clicks, skipping.`,
+ message: `Domain *${domain}* has been invalid for > 30 days but has links with clicks, skipping.`,
type: "cron",
});
- } else if (linksCount > 0) {
- const linksClicks = await prisma.link.aggregate({
- _sum: {
- clicks: true,
- },
- where: {
- domain,
- },
- });
- if (linksClicks._sum?.clicks) {
- return await log({
- message: `Domain *${domain}* has been invalid for > 30 days but has links with clicks, skipping.`,
- type: "cron",
- });
- }
}
// else, delete the domain
return await Promise.allSettled([
@@ -125,9 +113,7 @@ export const handleDomainUpdates = async ({
}
}),
log({
- message: `Domain *${domain}* has been invalid for > 30 days and ${
- linksCount > 0 ? "has links but no link clicks" : "has no links"
- }, deleting.`,
+ message: `Domain *${domain}* has been invalid for > 30 days andhas links but no link clicks, deleting.`,
type: "cron",
}),
emails.map((email) =>