Главная 80 → 30 мс, 40 запросов разом p95 2,98 → 1,12 с; «Подписки» 36 → 22 мс. Замер на копии живой базы (apps/web/scripts/bench-pages.ts). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
47 lines
3.2 KiB
TypeScript
47 lines
3.2 KiB
TypeScript
// PEP-216: times the data behind Home and /subscriptions on a COPY of the live database.
|
|
// PEPPA_DB=<copy> PEPPA_SECRET=x node apps/web/scripts/bench-pages.ts [userId] [rounds]
|
|
import { accountUsageForUser, agentsLine, getNotifyPrefs, isSuperadmin, pendingFeedbackCount, discussionUnread, userProjectIds, agentTaskSummary, listSubscriptions, onboardingChecklist, pendingFeedback, platformDelayCounts, poolOverviews, progressOverview, proposedCount, reviewCounts, listUserProjects } from "@peppa/core";
|
|
import { subscriptionRequestOffers, openSubscriptionRequests, backfillCodexAccounts, pendingLogin } from "@peppa/runner";
|
|
import { createDb } from "@peppa/db";
|
|
import { acceptInbox, activeSessions, inbox, navCounts } from "../lib/queries.ts";
|
|
|
|
const userId = Number(process.argv[2] ?? 2);
|
|
const rounds = Number(process.argv[3] ?? 3);
|
|
const db = createDb();
|
|
const user = (await db.query?.users?.findFirst?.({ where: (u: any, { eq }: any) => eq(u.id, userId) })) as any;
|
|
const rows: Record<string, number[]> = {};
|
|
async function time<T>(name: string, f: () => Promise<T>): Promise<T> {
|
|
const t = performance.now();
|
|
const r = await f();
|
|
(rows[name] ??= []).push(performance.now() - t);
|
|
return r;
|
|
}
|
|
for (let i = 0; i < rounds; i++) {
|
|
const projects = await time("listUserProjects", () => listUserProjects(db, userId));
|
|
await time("L getNotifyPrefs", () => getNotifyPrefs(db, userId));
|
|
await time("L isSuperadmin", () => isSuperadmin(db, user));
|
|
await time("L accountUsageForUser", () => accountUsageForUser(db, user));
|
|
await time("L agentsLine", () => agentsLine(db, user));
|
|
await time("L offers", () => subscriptionRequestOffers(db, user));
|
|
await time("L pendingFeedbackCount", () => pendingFeedbackCount(db));
|
|
await time("L discussionUnread", () => discussionUnread(db, userId));
|
|
await time("L userProjectIds", () => userProjectIds(db, userId));
|
|
await time("inbox", () => inbox(userId));
|
|
await time("acceptInbox", () => acceptInbox(userId));
|
|
await time("activeSessions", () => activeSessions(userId));
|
|
await time("onboarding", () => onboardingChecklist(db, user));
|
|
await time("progressOverview", () => progressOverview(db, userId));
|
|
await time("pendingFeedback", () => pendingFeedback(db));
|
|
await time("platformDelayCounts", () => platformDelayCounts(db));
|
|
await time("reviewCounts", () => reviewCounts(db, projects.map((p) => p.id)));
|
|
await time("proposedCount x projects", async () => { for (const p of projects) await (await import("@peppa/core")).proposedCount(db, p.id); });
|
|
await time("agentTaskSummary", () => agentTaskSummary(db));
|
|
await time("navCounts", () => navCounts(userId));
|
|
await time("SUBS backfillCodexAccounts", () => backfillCodexAccounts(db));
|
|
const subs = await time("SUBS listSubscriptions", () => listSubscriptions(db));
|
|
await time("SUBS pendingLogin x subs", async () => { for (const s of subs) await pendingLogin(db, s.id); });
|
|
await time("SUBS poolOverviews", () => poolOverviews(db));
|
|
await time("SUBS openSubscriptionRequests", () => openSubscriptionRequests(db));
|
|
}
|
|
for (const [k, v] of Object.entries(rows)) console.log(k.padEnd(32), Math.min(...v).toFixed(0).padStart(6), "ms min", Math.max(...v).toFixed(0).padStart(6), "ms max");
|