The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
removed getClicksForDomain function
Steven Tey30df371485e8
diff --git a/lib/cron/domains.tsx b/lib/cron/domains.tsxindex 2921d8fbcf..c28b0f0929 100644--- a/lib/cron/domains.tsx+++ b/lib/cron/domains.tsx@@ -4,7 +4,6 @@ import DomainDeleted from "emails/DomainDeleted";import { log } from "@/lib/utils";import { deleteDomainAndLinks } from "@/lib/api/domains";import prisma from "@/lib/prisma";-import { getClicksForDomain } from "../tinybird";export const handleDomainUpdates = async ({domain,@@ -47,6 +46,7 @@ export const handleDomainUpdates = async ({select: {slug: true,sentEmails: true,+ usage: true,users: {where: {role: "owner",@@ -80,19 +80,18 @@ export const handleDomainUpdates = async ({// if domain is invalid for more than 30 days, check if we can delete itif (invalidDays >= 30) {- // only delete if there are no links associated with the domain- if (linksCount > 0) {- // if there are links, check if there are any link clicks- const clicksForDomain = await getClicksForDomain(domain);- if (clicksForDomain > 0) {- await log(- `Domain *${domain}* has been invalid for > 30 days but has link clicks, not deleting.`,- "cron",- true,- );- return;- }+ // if there are still links associated with the domain,+ // and if the parent project has link clicks+ // don't delete the domain (manual inspection required)+ if (linksCount > 0 && project.usage > 0) {+ await log(+ `Domain *${domain}* has been invalid for > 30 days but has link clicks, not deleting.`,+ "cron",+ true,+ );+ return;}+ // else, delete the domain, but first,// check if the project needs to be deleted as wellconst deleteProjectAsWell = project._count.domains === 1;diff --git a/lib/tinybird.ts b/lib/tinybird.tsindex 399b7254d6..665544be73 100644--- a/lib/tinybird.ts+++ b/lib/tinybird.ts@@ -67,24 +67,3 @@ export async function recordClick(: []),]);}--export async function getClicksForDomain(domain: string) {- const response = await fetch(- `https://api.us-east.tinybird.co/v0/pipes/usage.json?domain=${domain}`,- {- headers: {- Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,- },- },- )- .then((res) => res.json())- .then((res) => res.data);-- let clicks = 0;- try {- clicks = response[0]["count()"];- } catch (e) {- console.log(e);- }- return clicks;-}