diff --git a/src/app/api/shorten/route.ts b/src/app/api/shorten/route.ts index 358600f..3853f0d 100644 --- a/src/app/api/shorten/route.ts +++ b/src/app/api/shorten/route.ts @@ -6,8 +6,10 @@ import { generateUniqueShortCode } from "@/lib/short-code"; import { generateQRCodeDataUrl } from "@/lib/qr"; export async function POST(req: Request) { + const t0 = performance.now(); try { const user = await getCurrentUser(); + const tAuth = performance.now(); const body = await req.json(); const { url, custom_code, password, tags, expires_at, display_on_portal } = body; @@ -62,6 +64,7 @@ export async function POST(req: Request) { // Auto-generate using configured default_url_length shortCode = await generateUniqueShortCode(); } + const tCodeGen = performance.now(); // Hash password if set let hashedPassword: string | null = null; @@ -111,13 +114,15 @@ export async function POST(req: Request) { tags: true, }, }); + const tDbCreate = performance.now(); // Build absolute short URL const appUrl = (process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000").replace(/\/$/, ""); const fullShortUrl = `${appUrl}/${shortCode}`; // Generate QR Code - const qrCodeDataUrl = await generateQRCodeDataUrl(fullShortUrl, { size: 280 }); + const qrCodeDataUrl = await generateQRCodeDataUrl(fullShortUrl, { size: 240 }); + const tQr = performance.now(); return NextResponse.json({ success: true, @@ -133,6 +138,13 @@ export async function POST(req: Request) { display_on_portal: createdUrl.displayOnPortal, tags: createdUrl.tags.map((t) => t.name), }, + _timings: { + auth_ms: Math.round(tAuth - t0), + code_gen_ms: Math.round(tCodeGen - tAuth), + db_create_ms: Math.round(tDbCreate - tCodeGen), + qr_ms: Math.round(tQr - tDbCreate), + total_server_ms: Math.round(tQr - t0), + }, }); } catch (error) { console.error("Shorten API error:", error); diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index e8a3414..8ef5ecf 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -10,4 +10,4 @@ export const prisma = log: process.env.NODE_ENV === "development" ? ["warn", "error"] : ["error"], }); -if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; +globalForPrisma.prisma = prisma;