The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add a few more changes
Steven Tey10729f5a3385
diff --git a/apps/web/app/api/cron/import/bitly/utils.ts b/apps/web/app/api/cron/import/bitly/utils.tsindex 12ed05c491..d391d175bb 100644--- a/apps/web/app/api/cron/import/bitly/utils.ts+++ b/apps/web/app/api/cron/import/bitly/utils.ts@@ -4,6 +4,7 @@ import {isCaseSensitiveDomain,} from "@/lib/api/case-sensitive-short-links";import { bulkCreateLinks } from "@/lib/api/links";+import { linkCache } from "@/lib/api/links/cache";import { qstash } from "@/lib/cron";import { redis } from "@/lib/upstash";import { sendEmail } from "@dub/email";@@ -204,31 +205,38 @@ export const importLinksFromBitly = async ({// bulk create linksawait bulkCreateLinks({ links: linksToCreate });- // only for buff.ly: check if previously created links (without case sensitivity) exists, if so, delete them- const previouslyCreatedLinks = await prisma.link.findMany({- where: {- shortLink: {- in: importedLinks.map((link) => link.shortLink),- },- },- select: {- id: true,- },- });-- console.log(- `Found ${previouslyCreatedLinks.length} buff.ly links that were imported without case sensitivity, deleting them...`,- );-- // delete links that exist as unhashed versions (only for buff.ly domain)- if (previouslyCreatedLinks.length) {- await prisma.link.deleteMany({+ // only for buff.ly: check if previously created links (without case sensitivity) exists, if so, delete them + expire their cache+ if (domains.includes("buff.ly")) {+ const previouslyCreatedLinks = await prisma.link.findMany({where: {- id: {- in: previouslyCreatedLinks.map((link) => link.id),+ shortLink: {+ in: importedLinks.map((link) => link.shortLink),},},+ select: {+ id: true,+ domain: true,+ key: true,+ },});++ console.log(+ `Found ${previouslyCreatedLinks.length} buff.ly links that were imported without case sensitivity, deleting them...`,+ );++ // delete links that exist as unhashed versions (only for buff.ly domain)+ if (previouslyCreatedLinks.length) {+ await Promise.allSettled([+ prisma.link.deleteMany({+ where: {+ id: {+ in: previouslyCreatedLinks.map((link) => link.id),+ },+ },+ }),+ linkCache.expireMany(previouslyCreatedLinks),+ ]);+ }}count += importedLinks.length;diff --git a/apps/web/app/api/links/crawl/bitly/route.ts b/apps/web/app/api/links/crawl/bitly/route.tsindex ddcdedfecc..05f6de8ef2 100644--- a/apps/web/app/api/links/crawl/bitly/route.ts+++ b/apps/web/app/api/links/crawl/bitly/route.ts@@ -1,11 +1,8 @@import { encodeKeyIfCaseSensitive } from "@/lib/api/case-sensitive-short-links";import { createId } from "@/lib/api/create-id";-import { ExpandedLink } from "@/lib/api/links";import { conn } from "@/lib/planetscale";-import { recordLink } from "@/lib/tinybird/record-link";import { redis } from "@/lib/upstash";import { getUrlFromStringIfValid, linkConstructorSimple } from "@dub/utils";-import { waitUntil } from "@vercel/functions";import { NextResponse } from "next/server";import { z } from "zod";@@ -89,16 +86,6 @@ export const POST = async (req: Request) => {],);- waitUntil(- recordLink({- ...newLink,- tenantId: null,- programId: null,- partnerId: null,- tags: [],- } as unknown as ExpandedLink),- );-return NextResponse.json(newLink);} catch (error) {console.error("[Bitly] Error creating link", error);diff --git a/apps/web/scripts/buffer/migrate-to-case-sensitive.ts b/apps/web/scripts/buffer/migrate-to-case-sensitive.tsindex 0fc51c5727..fd038cac50 100644--- a/apps/web/scripts/buffer/migrate-to-case-sensitive.ts+++ b/apps/web/scripts/buffer/migrate-to-case-sensitive.ts@@ -1,17 +1,15 @@-import { encodeKeyIfCaseSensitive } from "@/lib/api/case-sensitive-short-links";import { prisma } from "@dub/prisma";import { linkConstructorSimple } from "@dub/utils";import "dotenv-flow/config";+import { encodeKeyIfCaseSensitive } from "../../lib/api/case-sensitive-short-links";+import { linkCache } from "../../lib/api/links/cache";-const flatRatePartners: string[] = [];--const domain = "buff.ly";+const domain = "getacme.link";async function main() {const links = await prisma.link.findMany({where: {domain,-// TODO:// Fetch the links created using the Dub API},@@ -47,6 +45,9 @@ async function main() {console.log(`Updated link ${link.id} to ${newShortLink}`);}++ // expire the Redis cache for the links so it fetches the latest version from the database+ await linkCache.expireMany(links);}main();