The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
final changes
Steven Tey0bbe507b16fc
diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsxindex 6529626711..6cf5531531 100644--- a/components/app/modals/add-edit-link-modal/index.tsx+++ b/components/app/modals/add-edit-link-modal/index.tsx@@ -140,7 +140,7 @@ function AddEditLinkModal({<div className="inline-block w-full sm:max-w-md max-h-[calc(100vh-50px)] overflow-scroll align-middle transition-all transform bg-white sm:border sm:border-gray-200 shadow-xl sm:rounded-2xl"><buttononClick={() => setShowAddEditLinkModal(false)}- className="hidden sm:block absolute top-0 right-0 p-2 m-3 rounded-full group hover:bg-gray-100 text-gray-500 focus:outline-none active:scale-75 transition-all duration-75"+ className="hidden sm:block absolute top-0 right-0 p-2 m-3 rounded-full group hover:bg-gray-100 text-gray-500 focus:outline-none active:bg-gray-200 transition-all duration-75"><X className="w-5 h-5" /></button>diff --git a/components/shared/popover.tsx b/components/shared/popover.tsxindex 9841bb29d2..64a1eb281f 100644--- a/components/shared/popover.tsx+++ b/components/shared/popover.tsx@@ -96,11 +96,9 @@ export default function Popover({<PopoverPrimitive.ContentsideOffset={4}align={align}- className="hidden md:block animate-slide-up-fade items-center rounded-md overflow-hidden z-20 bg-white border border-gray-200 drop-shadow-lg"+ className="hidden md:block animate-slide-up-fade items-center rounded-md z-20 bg-white border border-gray-200 drop-shadow-lg">- <PopoverPrimitive.Arrow className="fill-current text-white" />{content}- <PopoverPrimitive.Arrow className="fill-current text-white" /></PopoverPrimitive.Content></PopoverPrimitive.Root></>diff --git a/lib/cron/usage.tsx b/lib/cron/usage.tsxindex 712d7d0e25..2555e7b8d2 100644--- a/lib/cron/usage.tsx+++ b/lib/cron/usage.tsx@@ -7,6 +7,20 @@ import { log } from "./utils";export const updateUsage = async () => {const users = await prisma.user.findMany({+ where: {+ NOT: {+ projects: {+ none: {},+ },+ },+ projects: {+ some: {+ project: {+ domainVerified: true,+ },+ },+ },+ },select: {id: true,email: true,@@ -14,21 +28,27 @@ export const updateUsage = async () => {stripeId: true,billingCycleStart: true,projects: {+ where: {+ role: "owner",+ project: {+ domainVerified: true,+ },+ },select: {project: {select: {id: true,domain: true,- domainVerified: true,},},},- where: {- role: "owner",- },},sentEmails: true,},+ orderBy: {+ usageUpdatedAt: "desc",+ },+ take: 50,});const response = await Promise.all(@@ -41,16 +61,11 @@ export const updateUsage = async () => {projects,sentEmails,}) => {- // if user has no projects, don't update usage- if (projects.length === 0) return;-const usageArr = await Promise.all(- projects.map(async ({ project: { id, domain, domainVerified } }) => {+ projects.map(async ({ project: { id, domain } }) => {return {id,- usage: domainVerified- ? await getUsage(domain, billingCycleStart)- : 0,+ usage: await getUsage(domain, billingCycleStart),};}),);@@ -92,6 +107,7 @@ export const updateUsage = async () => {},data: {usage: totalUsage,+ usageUpdatedAt: new Date(),// reset usage email warnings if it's a new billing cycle...(newBillingCycle && {sentEmails: {@@ -164,6 +180,26 @@ const getUsage = async (});results = await pipeline.exec();}++ const updateLinks = await Promise.all(+ links.map(({ key }, index) => {+ return prisma.link.update({+ where: {+ domain_key: {+ domain,+ key,+ },+ },+ data: {+ clicks: results[index],+ clicksUpdatedAt: new Date(),+ },+ });+ }),+ );++ console.log(updateLinks.length, "links updated for", domain);+const usage = results.reduce((acc, curr) => acc + curr, 0);return usage;};diff --git a/pages/api/cron/usage.ts b/pages/api/cron/usage.tsindex 2e7eaca322..a63d78e55d 100644--- a/pages/api/cron/usage.ts+++ b/pages/api/cron/usage.ts@@ -4,8 +4,7 @@ import { updateUsage } from "@/lib/cron/usage";/*** Cron to update the usage stats of each project.- * Runs once a day.- * TODO: Update the aggregated usage stats for a user and send them an email if they're over their limit.+ * Runs every 6 hours (might need to change this if we have more users).**/async function handler(_req: NextApiRequest, res: NextApiResponse) {diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex e9ec94eef5..b7c098c68f 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -28,6 +28,7 @@ model User {sentEmails SentEmail[]links Link[]createdAt DateTime @default(now())+ usageUpdatedAt DateTime @default(now())}model Account {