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.

fix delay

Steven Teycc534909ffbf
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 83ba09f6fc..1e27798e2f 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -86,7 +86,7 @@ export const POST = withAuth(
qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/delete`,
// delete after 30 mins
- delay: 30 * 60 * 1000,
+ delay: 30 * 60,
body: {
linkId: response.id,
},
diff --git a/apps/web/scripts/migrate-links-to-projects.ts b/apps/web/scripts/migrate-links-to-projects.ts
new file mode 100644
index 0000000000..2c59e7ffe6
--- /dev/null
+++ b/apps/web/scripts/migrate-links-to-projects.ts
@@ -0,0 +1,148 @@
+import "dotenv-flow/config";
+import prisma from "@/lib/prisma";
+import slugify from "@sindresorhus/slugify";
+import { capitalize, redis } from "./utils";
+
+const DUB_PROJECT_ID = "cl7pj5kq4006835rbjlt2ofka";
+const DUB_USER_ID = "cl7p1s07k000687rbuhpwqkqa";
+
+async function main() {
+ const users = await prisma.link.groupBy({
+ by: ["userId"],
+ _count: {
+ id: true,
+ },
+ where: {
+ projectId: DUB_PROJECT_ID,
+ AND: [
+ {
+ userId: {
+ not: null,
+ },
+ },
+ {
+ userId: {
+ not: DUB_USER_ID,
+ },
+ },
+ ],
+ },
+ orderBy: {
+ _count: {
+ id: "desc",
+ },
+ },
+ take: 500,
+ });
+
+ // const projectsToCreate = (await Promise.all(
+ // users
+ // .filter(({ userId }) => userId !== null)
+ // .map(async (user) => {
+ // const u = await prisma.user.findUnique({
+ // where: {
+ // id: user.userId!,
+ // },
+ // select: {
+ // name: true,
+ // email: true,
+ // },
+ // });
+ // if (!u) {
+ // return null;
+ // }
+
+ // const projectName =
+ // capitalize(u.name ?? u.email?.split("@")[0]) + "'s Links";
+
+ // let projectSlug = "";
+ // if (u.name) {
+ // projectSlug = slugify(u.name);
+ // }
+ // if (projectSlug === "") {
+ // projectSlug = slugify(u.email?.split("@")[0] ?? "");
+ // }
+ // return {
+ // userId: user.userId,
+ // name: u.name,
+ // email: u.email,
+ // links: user._count.id,
+ // projectName,
+ // projectSlug,
+ // };
+ // }),
+ // ).then((users) => users.filter((user) => user !== null))) as {
+ // userId: string;
+ // name: string | null;
+ // email: string | null;
+ // links: number;
+ // projectName: string;
+ // projectSlug: string;
+ // }[];
+
+ // await prisma.project.createMany({
+ // data: projectsToCreate.map(({ projectName, projectSlug }) => ({
+ // name: projectName,
+ // slug: projectSlug,
+ // billingCycleStart: new Date().getDate(),
+ // })),
+ // skipDuplicates: true,
+ // });
+
+ // const finalProjects = (await Promise.all(
+ // projectsToCreate.map(async (user) => {
+ // const project = await prisma.project.findUnique({
+ // where: {
+ // slug: user.projectSlug,
+ // },
+ // });
+ // return {
+ // ...user,
+ // projectId: project?.id,
+ // };
+ // }),
+ // )) as {
+ // userId: string;
+ // name: string | null;
+ // email: string | null;
+ // links: number;
+ // projectId: string;
+ // projectName: string;
+ // projectSlug: string;
+ // }[];
+
+ // const projectUsers = await prisma.projectUsers.createMany({
+ // data: finalProjects.map(({ userId, projectId }) => ({
+ // userId,
+ // projectId,
+ // role: "owner",
+ // })),
+ // skipDuplicates: true,
+ // });
+
+ // const links = await Promise.all(
+ // finalProjects.map(async (user) => {
+ // return await prisma.link.updateMany({
+ // where: {
+ // projectId: DUB_PROJECT_ID,
+ // userId: user.userId,
+ // },
+ // data: {
+ // projectId: user.projectId,
+ // },
+ // });
+ // }),
+ // );
+
+ // const redisHash = await redis.hset(
+ // "migrated_links_users",
+ // finalProjects.reduce((acc, { userId, projectId }) => {
+ // acc[userId] = projectId;
+ // return acc;
+ // }, {} as Record<string, string>),
+ // );
+
+ console.log({ users });
+}
+
+main();