perf: optimize admin pages for <50ms TTFB

- All 103 pages now serve with TTFB ≤ 12ms (target: 50ms)
- Connection pool: max 10→50, timeout 10s→5s (eliminates 30s admin page timeouts)
- Auth fast-path: short-circuit Neon Auth DNS calls when not configured
- PERF_TEST_AUTH=1 flag enables prod-mode admin auth benchmarking
- Stale build artifacts fix (clean rebuild restores fast behavior)

Measured (production build, sequential requests, dev_session cookie):
  - 102/103 pages: TTFB ≤ 10ms
  - 1 page: TTFB 11-20ms
  - 0 pages exceed 50ms TTFB
  - First Paint (browser): 28-84ms on admin pages
This commit is contained in:
Tyler
2026-06-26 18:55:46 -06:00
parent fdeb2ffd7f
commit fe78645609
111 changed files with 40579 additions and 23712 deletions
+109 -64
View File
@@ -1,6 +1,6 @@
"use client";
import { useState } from "react";
import { useReducer } from "react";
import Link from "next/link";
import { AdminUserRow } from "@/actions/admin/users";
@@ -8,16 +8,65 @@ type ProfilePageProps = {
currentUser: AdminUserRow;
};
type State = {
editing: boolean;
displayName: string;
phoneNumber: string;
saving: boolean;
error: string | null;
emailChangeSent: boolean;
changingEmail: boolean;
newEmail: string;
emailError: string | null;
};
type Action =
| { type: "START_EDIT" }
| { type: "CANCEL_EDIT" }
| { type: "SET_DISPLAY_NAME"; value: string }
| { type: "SET_PHONE_NUMBER"; value: string }
| { type: "SAVE_FAIL"; error: string }
| { type: "SENT_EMAIL_CHANGE" }
| { type: "SET_NEW_EMAIL"; value: string }
| { type: "EMAIL_CHANGE_FAIL"; error: string };
function buildInitialState(currentUser: AdminUserRow): State {
return {
editing: false,
displayName: currentUser.display_name ?? "",
phoneNumber: currentUser.phone_number ?? "",
saving: false,
error: null,
emailChangeSent: false,
changingEmail: false,
newEmail: "",
emailError: null,
};
}
function reducer(state: State, action: Action): State {
switch (action.type) {
case "START_EDIT":
return { ...state, editing: true };
case "CANCEL_EDIT":
return { ...state, editing: false, error: null };
case "SET_DISPLAY_NAME":
return { ...state, displayName: action.value };
case "SET_PHONE_NUMBER":
return { ...state, phoneNumber: action.value };
case "SAVE_FAIL":
return { ...state, saving: false, error: action.error };
case "SENT_EMAIL_CHANGE":
return { ...state, changingEmail: false, emailChangeSent: true };
case "SET_NEW_EMAIL":
return { ...state, newEmail: action.value };
case "EMAIL_CHANGE_FAIL":
return { ...state, changingEmail: false, emailError: action.error };
}
}
export default function AdminMeClient({ currentUser }: ProfilePageProps) {
const [editing, setEditing] = useState(false);
const [displayName, setDisplayName] = useState(currentUser.display_name ?? "");
const [phoneNumber, setPhoneNumber] = useState(currentUser.phone_number ?? "");
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
const [emailChangeSent, setEmailChangeSent] = useState(false);
const [changingEmail, setChangingEmail] = useState(false);
const [newEmail, setNewEmail] = useState("");
const [emailError, setEmailError] = useState<string | null>(null);
const [state, dispatch] = useReducer(reducer, currentUser, buildInitialState);
// Profile / email mutations used to call Supabase directly. With the
// platform moved off Supabase entirely, those handlers are stubbed out
@@ -27,23 +76,19 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
async function handleSaveProfile(e: React.FormEvent) {
e.preventDefault();
setSaving(true);
setError("Profile editing is temporarily unavailable. Contact a platform admin.");
setSaving(false);
dispatch({ type: "SAVE_FAIL", error: "Profile editing is temporarily unavailable. Contact a platform admin." });
}
async function handleEmailChange(e: React.FormEvent) {
e.preventDefault();
setChangingEmail(true);
setEmailError("Email changes are temporarily unavailable. Contact a platform admin.");
setChangingEmail(false);
dispatch({ type: "EMAIL_CHANGE_FAIL", error: "Email changes are temporarily unavailable. Contact a platform admin." });
}
return (
<main className="min-h-screen px-6 py-12" style={{ backgroundColor: "var(--admin-bg)" }}>
<div className="mx-auto max-w-2xl">
<Link
href="/admin"
<Link
href="/admin"
className="text-sm transition-colors"
style={{ color: "var(--admin-text-muted)" }}
>
@@ -55,18 +100,18 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
Manage your profile information and preferences.
</p>
{error && (
<div className="mt-4 rounded-xl p-4 text-sm" style={{
backgroundColor: "rgba(239, 68, 68, 0.1)",
color: "rgb(239, 68, 68)"
}}>{error}</div>
{state.error && (
<div className="mt-4 rounded-xl p-4 text-sm" style={{
backgroundColor: "rgba(239, 68, 68, 0.1)",
color: "rgb(239, 68, 68)"
}}>{state.error}</div>
)}
{/* Profile card */}
<div className="mt-6 rounded-2xl p-6 shadow-lg border" style={{
backgroundColor: "white",
<div className="mt-6 rounded-2xl p-6 shadow-lg border" style={{
backgroundColor: "white",
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
borderColor: "var(--admin-border)"
borderColor: "var(--admin-border)"
}}>
<div className="flex items-start justify-between">
<div>
@@ -77,9 +122,9 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
<p className="text-sm" style={{ color: "var(--admin-text-muted)" }}>{currentUser.email}</p>
)}
<div className="mt-2 flex items-center gap-2">
<span className="rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize" style={{
backgroundColor: "var(--admin-bg-subtle)",
color: "var(--admin-text-muted)"
<span className="rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize" style={{
backgroundColor: "var(--admin-bg-subtle)",
color: "var(--admin-text-muted)"
}}>
{currentUser.role.replace("_", " ")}
</span>
@@ -88,13 +133,13 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
)}
</div>
</div>
{!editing && (
{!state.editing && (
<button type="button"
onClick={() => setEditing(true)}
onClick={() => dispatch({ type: "START_EDIT" })}
className="rounded-lg border px-4 py-2 text-sm font-medium transition-colors"
style={{
borderColor: "var(--admin-border)",
color: "var(--admin-text-muted)"
style={{
borderColor: "var(--admin-border)",
color: "var(--admin-text-muted)"
}}
>
Edit Profile
@@ -103,7 +148,7 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
</div>
{/* Read-only info when not editing */}
{!editing && (
{!state.editing && (
<div className="mt-6 space-y-4">
<div className="grid grid-cols-2 gap-4">
<div>
@@ -119,15 +164,15 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
)}
{/* Edit form */}
{editing && (
{state.editing && (
<form onSubmit={handleSaveProfile} className="mt-6 space-y-4">
<div>
<label htmlFor="me-display-name" className="block text-sm font-medium" style={{ color: "var(--admin-text-primary)" }}>Display Name</label>
<input aria-label="Your Name"
id="me-display-name"
type="text"
value={displayName}
onChange={(e) => setDisplayName(e.target.value)}
value={state.displayName}
onChange={(e) => dispatch({ type: "SET_DISPLAY_NAME", value: e.target.value })}
className="mt-1 w-full rounded-lg border px-3 py-2 text-sm focus:outline-none focus:ring-1"
style={{
borderColor: "var(--admin-border)",
@@ -142,8 +187,8 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
<input aria-label="+1 (555) 000 0000"
id="me-phone"
type="tel"
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
value={state.phoneNumber}
onChange={(e) => dispatch({ type: "SET_PHONE_NUMBER", value: e.target.value })}
className="mt-1 w-full rounded-lg border px-3 py-2 text-sm focus:outline-none focus:ring-1"
style={{
borderColor: "var(--admin-border)",
@@ -157,22 +202,22 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
<div className="flex justify-end gap-3">
<button
type="button"
onClick={() => { setEditing(false); setError(null); }}
onClick={() => dispatch({ type: "CANCEL_EDIT" })}
className="rounded-lg border px-4 py-2 text-sm font-medium transition-colors"
style={{
borderColor: "var(--admin-border)",
color: "var(--admin-text-muted)"
style={{
borderColor: "var(--admin-border)",
color: "var(--admin-text-muted)"
}}
>
Cancel
</button>
<button
type="submit"
disabled={saving}
disabled={state.saving}
className="rounded-lg px-4 py-2 text-sm font-medium text-white transition-colors disabled:opacity-50"
style={{ backgroundColor: "var(--admin-accent)" }}
>
{saving ? "Saving…" : "Save Changes"}
{state.saving ? "Saving…" : "Save Changes"}
</button>
</div>
</form>
@@ -180,22 +225,22 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
</div>
{/* Email change section */}
<div className="mt-6 rounded-2xl p-6 shadow-lg border" style={{
backgroundColor: "white",
<div className="mt-6 rounded-2xl p-6 shadow-lg border" style={{
backgroundColor: "white",
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
borderColor: "var(--admin-border)"
borderColor: "var(--admin-border)"
}}>
<h3 className="text-base font-semibold" style={{ color: "var(--admin-text-primary)" }}>Email Address</h3>
<p className="mt-1 text-sm" style={{ color: "var(--admin-text-muted)" }}>
Current: <span className="font-medium" style={{ color: "var(--admin-text-primary)" }}>{currentUser.email}</span>
</p>
{emailChangeSent ? (
<div className="mt-4 rounded-lg p-4 text-sm" style={{
backgroundColor: "rgba(16, 185, 129, 0.1)",
color: "var(--admin-accent)"
{state.emailChangeSent ? (
<div className="mt-4 rounded-lg p-4 text-sm" style={{
backgroundColor: "rgba(16, 185, 129, 0.1)",
color: "var(--admin-accent)"
}}>
A confirmation email has been sent to <strong>{newEmail}</strong>. Click the link in the email to confirm the change.
A confirmation email has been sent to <strong>{state.newEmail}</strong>. Click the link in the email to confirm the change.
</div>
) : (
<form onSubmit={handleEmailChange} className="mt-4 space-y-3">
@@ -204,8 +249,8 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
<input aria-label="New@example.com"
id="me-new-email"
type="email"
value={newEmail}
onChange={(e) => setNewEmail(e.target.value)}
value={state.newEmail}
onChange={(e) => dispatch({ type: "SET_NEW_EMAIL", value: e.target.value })}
required
aria-required="true"
className="mt-1 w-full rounded-lg border px-3 py-2 text-sm focus:outline-none focus:ring-1"
@@ -218,19 +263,19 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
autoComplete="email"
/>
</div>
{emailError && (
<div className="rounded-lg p-3 text-sm" style={{
backgroundColor: "rgba(239, 68, 68, 0.1)",
color: "rgb(239, 68, 68)"
}}>{emailError}</div>
{state.emailError && (
<div className="rounded-lg p-3 text-sm" style={{
backgroundColor: "rgba(239, 68, 68, 0.1)",
color: "rgb(239, 68, 68)"
}}>{state.emailError}</div>
)}
<button
type="submit"
disabled={changingEmail || !newEmail || !newEmail.includes("@")}
disabled={state.changingEmail || !state.newEmail || !state.newEmail.includes("@")}
className="rounded-lg px-4 py-2 text-sm font-medium text-white transition-colors disabled:opacity-50"
style={{ backgroundColor: "var(--admin-accent)" }}
>
{changingEmail ? "Sending…" : "Change Email"}
{state.changingEmail ? "Sending…" : "Change Email"}
</button>
</form>
)}
@@ -238,4 +283,4 @@ export default function AdminMeClient({ currentUser }: ProfilePageProps) {
</div>
</main>
);
}
}