The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Optimize `Link` table
Steven Teyefc8b0553935
diff --git a/apps/web/app/api/admin/links/count/route.ts b/apps/web/app/api/admin/links/count/route.tsindex 907156b5f8..fca4f33d33 100644--- a/apps/web/app/api/admin/links/count/route.ts+++ b/apps/web/app/api/admin/links/count/route.ts@@ -17,9 +17,6 @@ export const GET = withAdmin(async ({ searchParams }) => {const tagIds = tagId ? tagId.split(",") : [];const linksWhere = {- userId: {- not: LEGAL_USER_ID,- },// when filtering by domain, only filter by domain if the filter group is not "Domains"...(domain && groupBy !== "domain"? {@@ -30,6 +27,9 @@ export const GET = withAdmin(async ({ searchParams }) => {in: DUB_DOMAINS_ARRAY,},}),+ userId: {+ not: LEGAL_USER_ID,+ },...(search && {OR: [{diff --git a/apps/web/app/api/admin/links/route.ts b/apps/web/app/api/admin/links/route.tsindex 310eb9c140..0b1d7c86d4 100644--- a/apps/web/app/api/admin/links/route.ts+++ b/apps/web/app/api/admin/links/route.ts@@ -19,6 +19,13 @@ export const GET = withAdmin(async ({ searchParams }) => {const response = await prisma.link.findMany({where: {+ ...(domain+ ? { domain }+ : {+ domain: {+ in: DUB_DOMAINS_ARRAY,+ },+ }),OR: [{userId: {@@ -29,13 +36,6 @@ export const GET = withAdmin(async ({ searchParams }) => {userId: null,},],- ...(domain- ? { domain }- : {- domain: {- in: DUB_DOMAINS_ARRAY,- },- }),...(search &&(search.startsWith("https://")? {diff --git a/apps/web/lib/api/links/get-links-count.ts b/apps/web/lib/api/links/get-links-count.tsindex 966d116992..a5ba92519d 100644--- a/apps/web/lib/api/links/get-links-count.ts+++ b/apps/web/lib/api/links/get-links-count.ts@@ -30,7 +30,6 @@ export async function getLinksCount({const linksWhere = {projectId: workspaceId,- archived: showArchived ? undefined : false,AND: [...(folderIds? [@@ -63,6 +62,7 @@ export async function getLinksCount({]: []),],+ archived: showArchived ? undefined : false,...(domain &&groupBy !== "domain" && {domain,diff --git a/apps/web/lib/api/links/get-links-for-workspace.ts b/apps/web/lib/api/links/get-links-for-workspace.tsindex 790ddaf80e..f229966dfd 100644--- a/apps/web/lib/api/links/get-links-for-workspace.ts+++ b/apps/web/lib/api/links/get-links-for-workspace.ts@@ -60,7 +60,6 @@ export async function getLinksForWorkspace({const links = await prisma.link.findMany({where: {projectId: workspaceId,- archived: showArchived ? undefined : false,AND: [...(folderIds? [@@ -102,6 +101,7 @@ export async function getLinksForWorkspace({]: []),],+ archived: showArchived ? undefined : false,...(domain && { domain }),...(withTags && {tags: {diff --git a/packages/prisma/schema/link.prisma b/packages/prisma/schema/link.prismaindex 2d556eb8c4..1472946029 100644--- a/packages/prisma/schema/link.prisma+++ b/packages/prisma/schema/link.prisma@@ -6,7 +6,7 @@ model Link {shortLink String @unique @db.VarChar(400) // new column for the full short linkarchived Boolean @default(false) // whether the link is archived or notexpiresAt DateTime? // when the link expires – stored on Redis via ttl- expiredUrl String? @db.LongText // URL to redirect the user to when the link is expired+ expiredUrl String? @db.Text // URL to redirect the user to when the link is expiredpassword String? // password to access the linktrackConversion Boolean @default(false) // whether to track conversions or not@@ -14,7 +14,7 @@ model Link {title String? // OG title for the link (e.g. Dub.co - Open-Source Link Management Infrastructure)description String? @db.VarChar(280) // OG description for the link (e.g. An open-source link management tool for modern marketing teams to create, share, and track short links.)image String? @db.LongText // OG image for the link (e.g. https://d.to/og)- video String? @db.LongText // OG video for the link+ video String? @db.Text // OG video for the link// UTM parametersutm_source String? // UTM source for the link (e.g. youtube.com)@@ -29,8 +29,8 @@ model Link {doIndex Boolean @default(false) // we don't index short links by default// Custom device targeting- ios String? @db.LongText // custom link for iOS devices- android String? @db.LongText // custom link for Android devices+ ios String? @db.Text // custom link for iOS devices+ android String? @db.Text // custom link for Android devicesgeo Json? @db.Json // custom link for specific countries// User who created the link@@ -68,7 +68,7 @@ model Link {webhooks LinkWebhook[]// Comments on the particular shortlink- comments String? @db.LongText+ comments String? @db.Textdashboard Dashboard?partnerId String?@@ -79,9 +79,9 @@ model Link {commissions Commission[]@@unique([domain, key])- @@unique([projectId, externalId])+ @@index([projectId, folderId, createdAt(sort: Desc)])@@index([projectId, archived, folderId, createdAt(sort: Desc)])+ @@unique([projectId, externalId])@@index([programId, partnerId])@@index(folderId) // used in /api/folders- @@index(userId) // used in /api/admin/links}