The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update record-click.ts
Steven Tey39dd28d4a1b5
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.tsindex 63e249b13e..69292c7f74 100644--- a/apps/web/lib/tinybird/record-click.ts+++ b/apps/web/lib/tinybird/record-click.ts@@ -15,7 +15,6 @@ import {getIdentityHash,} from "../middleware/utils";import { conn } from "../planetscale";-import { prismaEdge } from "../prisma/edge";import { ratelimit } from "../upstash";import { webhookCache } from "../webhook/cache";import { sendWebhooks } from "../webhook/qstash";@@ -115,7 +114,7 @@ export async function recordClick({referer_url: referer || "(direct)",};- const [_tb, link, _project] = await Promise.allSettled([+ await Promise.allSettled([fetch(`${process.env.TINYBIRD_API_URL}/v0/events?name=dub_click_events&wait=true`,{@@ -128,13 +127,11 @@ export async function recordClick({).then((res) => res.json()),// increment the click count for the link (based on their ID)- prismaEdge.link.update({- where: { id: linkId },- data: {- clicks: { increment: 1 },- lastClicked: new Date(),- },- }),+ // we have to use planetscale connection directly (not prismaEdge) because of connection pooling+ conn.execute(+ "UPDATE Link SET clicks = clicks + 1, lastClicked = NOW() WHERE id = ?",+ [linkId],+ ),// if the link has a destination URL, increment the usage count for the workspace// and then we have a cron that will reset it at the start of new billing cycleurl &&@@ -162,13 +159,9 @@ export async function recordClick({// @ts-ignoredata: transformClickEventData({...clickData,- // on the super rare case that the link failed to fetch, we'll use the link ID as a fallback- link:- link.status === "fulfilled"- ? link.value- : {- id: linkId,- },+ link: {+ id: linkId,+ },}),});}