The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
convert dub.sh to runtime = 'edge'
Steven Tey083a16134378
diff --git a/app/dub.sh/page.tsx b/app/dub.sh/page.tsxindex 04eab32b48..8a06370686 100644--- a/app/dub.sh/page.tsx+++ b/app/dub.sh/page.tsx@@ -8,6 +8,8 @@ import OSS from "#/ui/home/oss";import Testimonials from "#/ui/home/testimonials";import Changelog from "#/ui/home/changelog";+export const runtime = "edge";+export default function Home() {return (<>diff --git a/app/ui/home/stats.tsx b/app/ui/home/stats.tsxindex b34dc75681..5720e19aeb 100644--- a/app/ui/home/stats.tsx+++ b/app/ui/home/stats.tsx@@ -1,25 +1,13 @@import { unstable_cache } from "next/cache";-import prisma from "#/lib/prisma";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 unstable_cache(- async () => {- return Promise.all([- prisma.domain.count({- where: {- verified: true,- },- }),- prisma.link.count(),- ]);- },- [],- {- revalidate: 900,- },- )();+ const [domains, shortlinks] = await Promise.all([+ getTotalVerifiedDomains(),+ getTotalLinks(),+ ]);const clicks = await fetch(`https://api.us-east.tinybird.co/v0/pipes/all_clicks.json`,diff --git a/app/ui/home/testimonials.tsx b/app/ui/home/testimonials.tsxindex 6475d0d663..954f9d9c14 100644--- a/app/ui/home/testimonials.tsx+++ b/app/ui/home/testimonials.tsx@@ -1,10 +1,10 @@import { unstable_cache } from "next/cache";-import prisma from "#/lib/prisma";import { nFormatter } from "#/lib/utils";import MaxWidthWrapper from "@/components/shared/max-width-wrapper";import TestimonialsMobile from "./testimonials-mobile";import Tweet from "#/ui/tweet";import { getTweet, Tweet as TweetProps } from "react-tweet/api";+import { getTotalUsers } from "#/lib/planetscale";const tweets = ["1631671657617059842",@@ -25,15 +25,7 @@ const tweets = [];export default async function Testimonials() {- const userCount = await unstable_cache(- async () => {- return prisma.user.count();- },- [],- {- revalidate: 300,- },- )();+ const userCount = await getTotalUsers();const tweetsData = (await Promise.all(tweets.map((id) => getTweet(id)))diff --git a/lib/planetscale.ts b/lib/planetscale.tsindex eb316d9dcf..52641e7fa1 100644--- a/lib/planetscale.ts+++ b/lib/planetscale.ts@@ -29,3 +29,32 @@ export const getLinkViaEdge = async (domain: string, key: string) => {}): null;};++export const getTotalVerifiedDomains = async () => {+ if (!conn) return 1000;++ const { rows } = await conn.execute(+ "SELECT COUNT(*) FROM Domain WHERE verified = 1",+ );+ return rows && Array.isArray(rows) && rows.length > 0+ ? rows[0]["count(*)"]+ : 1000;+};++export const getTotalLinks = async () => {+ if (!conn) return 20000;++ const { rows } = await conn.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;++ const { rows } = await conn.execute("SELECT COUNT(*) FROM User");+ return rows && Array.isArray(rows) && rows.length > 0+ ? rows[0]["count(*)"]+ : 10000;+};