The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
removed edge runtime until this is fixed: https://github.com/vercel/next.js/issues/42112#issuecomment-1656864603
Steven Tey38b313a05269
diff --git a/app/dub.sh/layout.tsx b/app/dub.sh/layout.tsxindex 0b2e924df4..a0b1f5cdab 100644--- a/app/dub.sh/layout.tsx+++ b/app/dub.sh/layout.tsx@@ -5,8 +5,6 @@ import Footer from "#/ui/home/footer";import Background from "#/ui/home/background";import MobileNav from "#/ui/home/nav-mobile";-export const runtime = "edge";-export default function MarketingLayout({children,modal,diff --git a/app/ui/home/stats.tsx b/app/ui/home/stats.tsxindex e7514e3db1..b472cc4d3a 100644--- a/app/ui/home/stats.tsx+++ b/app/ui/home/stats.tsx@@ -1,26 +1,22 @@+import { getTotalLinks, getTotalVerifiedDomains } from "#/lib/planetscale";import MaxWidthWrapper from "@/components/shared/max-width-wrapper";import { nFormatter } from "#/lib/utils";-import { getTotalVerifiedDomains, getTotalLinks } from "#/lib/planetscale";export default async function Stats() {- const [domains, shortlinks] = await Promise.all([+ const [domains, shortlinks, clicks] = await Promise.all([getTotalVerifiedDomains(),getTotalLinks(),- ]);-- const clicks = await fetch(- `https://api.us-east.tinybird.co/v0/pipes/all_clicks.json`,- {+ fetch(`https://api.us-east.tinybird.co/v0/pipes/all_clicks.json`, {headers: {Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,},next: {revalidate: 300,},- },- )- .then((res) => res.json())- .then((res) => res.data[0]["count(timestamp)"]);+ })+ .then((res) => res.json())+ .then((res) => res.data[0]["count(timestamp)"]),+ ]);return (<StatsSection domains={domains} shortlinks={shortlinks} clicks={clicks} />diff --git a/app/ui/home/testimonials.tsx b/app/ui/home/testimonials.tsxindex ae022d1549..ca1468708a 100644--- a/app/ui/home/testimonials.tsx+++ b/app/ui/home/testimonials.tsx@@ -24,11 +24,12 @@ const tweets = [];export default async function Testimonials() {- const userCount = await getTotalUsers();-- const tweetsData = (- await Promise.all(tweets.map((id) => getTweet(id)))- ).filter((t) => t) as TweetProps[];+ const [userCount, tweetsData] = await Promise.all([+ getTotalUsers(),+ (+ await Promise.all(tweets.map((id) => getTweet(id)))+ ).filter((t) => t) as TweetProps[],+ ]);return (<MaxWidthWrapper className="pt-20">diff --git a/lib/planetscale.ts b/lib/planetscale.tsindex 52641e7fa1..478c43893c 100644--- a/lib/planetscale.ts+++ b/lib/planetscale.ts@@ -6,6 +6,22 @@ export const pscale_config = {export const conn = process.env.DATABASE_URL ? connect(pscale_config) : null;+// custom cached connection that sets next.revalidate to 900s+export const cachedConn = process.env.DATABASE_URL+ ? connect({+ ...pscale_config,+ fetch: (url, init) => {+ // set next.revalidate+ return fetch(url, {+ ...init,+ next: {+ revalidate: 900,+ },+ });+ },+ })+ : null;+export const getLinkViaEdge = async (domain: string, key: string) => {if (!conn) return null;@@ -31,9 +47,9 @@ export const getLinkViaEdge = async (domain: string, key: string) => {};export const getTotalVerifiedDomains = async () => {- if (!conn) return 1000;+ if (!cachedConn) return 1000;- const { rows } = await conn.execute(+ const { rows } = await cachedConn.execute("SELECT COUNT(*) FROM Domain WHERE verified = 1",);return rows && Array.isArray(rows) && rows.length > 0@@ -42,18 +58,18 @@ export const getTotalVerifiedDomains = async () => {};export const getTotalLinks = async () => {- if (!conn) return 20000;+ if (!cachedConn) return 20000;- const { rows } = await conn.execute("SELECT COUNT(*) FROM Link");+ const { rows } = await cachedConn.execute("SELECT COUNT(*) FROM Link");return rows && Array.isArray(rows) && rows.length > 0? rows[0]["count(*)"]: 20000;};export const getTotalUsers = async () => {- if (!conn) return 10000;+ if (!cachedConn) return 10000;- const { rows } = await conn.execute("SELECT COUNT(*) FROM User");+ const { rows } = await cachedConn.execute("SELECT COUNT(*) FROM User");return rows && Array.isArray(rows) && rows.length > 0? rows[0]["count(*)"]: 10000;