Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

chore: cleanup link migration

Steven Tey768afa4eed16
diff --git a/apps/web/app/api/cron/migrate/route.ts b/apps/web/app/api/cron/migrate/route.ts
index a1d07d695a..66517f8008 100644
--- a/apps/web/app/api/cron/migrate/route.ts
+++ b/apps/web/app/api/cron/migrate/route.ts
@@ -25,9 +25,6 @@ export async function POST(req: Request) {
projectId: "cm05wnnpo000711ztj05wwdbu",
archived: false,
folderId: "fold_LIZsdjTgFVbQVGYSUmYAi5vT",
- createdAt: {
- lte: new Date("2025-02-27T00:00:00.000Z"),
- },
};
const links = await prisma.link.findMany({
@@ -38,9 +35,6 @@ export async function POST(req: Request) {
createdAt: true,
},
take: 1000,
- orderBy: {
- createdAt: "desc",
- },
});
if (!links.length) {
@@ -64,13 +58,6 @@ export async function POST(req: Request) {
`Final deleted link: ${finalDeletedLink.key} (${new Date(finalDeletedLink.createdAt).toISOString()})`,
);
- if (finalDeletedLink.createdAt <= new Date("2024-05-18T11:54:08.000Z")) {
- console.log("Reached previously imported links point, pausing for now...");
- return NextResponse.json({
- status: `Reached previously imported links point, pausing for now...`,
- });
- }
-
await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/migrate`,
method: "POST",
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 6d7fa0ba30..763d7ce2f3 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -86,44 +86,29 @@ export default async function LinkMiddleware(
});
if (!linkData) {
- // TODO: remove this once everything is migrated over and are case-sensitive
- // don't forget to remove ignoreCaseSensitivity too, it won't be needed anymore
+ // TODO: remove this once everything is migrated over
if (domain === "buff.ly") {
- // double check if the regular version exists
- linkData = await getLinkViaEdge({
- domain,
- key,
- ignoreCaseSensitivity: true,
- });
-
- if (!linkData) {
- return NextResponse.rewrite(
- new URL(`/api/links/crawl/bitly/${domain}/${key}`, req.url),
- );
- }
+ return NextResponse.rewrite(
+ new URL(`/api/links/crawl/bitly/${domain}/${key}`, req.url),
+ );
}
- if (!linkData) {
- // check if domain has notFoundUrl configured
- const domainData = await getDomainViaEdge(domain);
- if (domainData?.notFoundUrl) {
- return NextResponse.redirect(domainData.notFoundUrl, {
- headers: {
- ...DUB_HEADERS,
- "X-Robots-Tag": "googlebot: noindex",
- // pass the Referer value to the not found URL
- Referer: req.url,
- },
- status: 302,
- });
- } else {
- return NextResponse.rewrite(
- new URL(`/${domain}/not-found`, req.url),
- {
- headers: DUB_HEADERS,
- },
- );
- }
+ // check if domain has notFoundUrl configured
+ const domainData = await getDomainViaEdge(domain);
+ if (domainData?.notFoundUrl) {
+ return NextResponse.redirect(domainData.notFoundUrl, {
+ headers: {
+ ...DUB_HEADERS,
+ "X-Robots-Tag": "googlebot: noindex",
+ // pass the Referer value to the not found URL
+ Referer: req.url,
+ },
+ status: 302,
+ });
+ } else {
+ return NextResponse.rewrite(new URL(`/${domain}/not-found`, req.url), {
+ headers: DUB_HEADERS,
+ });
}
}
diff --git a/apps/web/lib/planetscale/check-if-key-exists.ts b/apps/web/lib/planetscale/check-if-key-exists.ts
index 5d72cf7060..9069c7abee 100644
--- a/apps/web/lib/planetscale/check-if-key-exists.ts
+++ b/apps/web/lib/planetscale/check-if-key-exists.ts
@@ -8,20 +8,17 @@ import { conn } from "./connection";
export const checkIfKeyExists = async ({
domain,
key,
- ignoreCaseSensitivity = false,
}: {
domain: string;
key: string;
- ignoreCaseSensitivity?: boolean;
}) => {
const isCaseSensitive = isCaseSensitiveDomain(domain);
- const keyToQuery =
- isCaseSensitive && !ignoreCaseSensitivity
- ? // for case sensitive domains, we need to encode the key
- encodeKey(key)
- : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded
- // (cause that's how we store it in MySQL)
- punyEncode(decodeURIComponent(key));
+ const keyToQuery = isCaseSensitive
+ ? // for case sensitive domains, we need to encode the key
+ encodeKey(key)
+ : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded
+ // (cause that's how we store it in MySQL)
+ punyEncode(decodeURIComponent(key));
const { rows } =
(await conn.execute(
diff --git a/apps/web/lib/planetscale/get-link-via-edge.ts b/apps/web/lib/planetscale/get-link-via-edge.ts
index c9d365e610..3c04dada4a 100644
--- a/apps/web/lib/planetscale/get-link-via-edge.ts
+++ b/apps/web/lib/planetscale/get-link-via-edge.ts
@@ -10,20 +10,17 @@ import { EdgeLinkProps } from "./types";
export const getLinkViaEdge = async ({
domain,
key,
- ignoreCaseSensitivity = false,
}: {
domain: string;
key: string;
- ignoreCaseSensitivity?: boolean;
}) => {
const isCaseSensitive = isCaseSensitiveDomain(domain);
- const keyToQuery =
- isCaseSensitive && !ignoreCaseSensitivity
- ? // for case sensitive domains, we need to encode the key
- encodeKey(key)
- : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded
- // (cause that's how we store it in MySQL)
- punyEncode(decodeURIComponent(key));
+ const keyToQuery = isCaseSensitive
+ ? // for case sensitive domains, we need to encode the key
+ encodeKey(key)
+ : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded
+ // (cause that's how we store it in MySQL)
+ punyEncode(decodeURIComponent(key));
const { rows } =
(await conn.execute("SELECT * FROM Link WHERE domain = ? AND `key` = ?", [
diff --git a/apps/web/lib/planetscale/get-random-key.ts b/apps/web/lib/planetscale/get-random-key.ts
index 06e27fae45..04dd769b26 100644
--- a/apps/web/lib/planetscale/get-random-key.ts
+++ b/apps/web/lib/planetscale/get-random-key.ts
@@ -1,5 +1,4 @@
import { nanoid } from "@dub/utils";
-import { isCaseSensitiveDomain } from "../api/links/case-sensitivity";
import { checkIfKeyExists } from "./check-if-key-exists";
export async function getRandomKey({
@@ -23,16 +22,6 @@ export async function getRandomKey({
// by the off chance that key already exists
return getRandomKey({ domain, prefix, long });
} else {
- if (isCaseSensitiveDomain(domain)) {
- const unencodedExists = await checkIfKeyExists({
- domain,
- key,
- ignoreCaseSensitivity: true,
- });
- if (unencodedExists) {
- return getRandomKey({ domain, prefix, long });
- }
- }
return key;
}
}
diff --git a/apps/web/scripts/buffer/delete-old-links.ts b/apps/web/scripts/buffer/delete-old-links.ts
index 74acd31c74..bca9fe3c7a 100644
--- a/apps/web/scripts/buffer/delete-old-links.ts
+++ b/apps/web/scripts/buffer/delete-old-links.ts
@@ -7,9 +7,6 @@ async function main() {
projectId: "cm05wnnpo000711ztj05wwdbu",
archived: false,
folderId: "fold_LIZsdjTgFVbQVGYSUmYAi5vT",
- createdAt: {
- lte: new Date("2025-02-27T00:00:00.000Z"),
- },
};
const links = await prisma.link.findMany({
@@ -20,9 +17,6 @@ async function main() {
createdAt: true,
},
take: 1000,
- orderBy: {
- createdAt: "desc",
- },
});
if (!links.length) {