peppa/apps/web/app/(app)/layout.tsx
peppa-bot 65a5d15aae PEP-216: Главная и «Подписки» без задержек — прогресс без запроса на проект, поток, индекс событий
Главная 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>
2026-11-20 16:31:10 +05:00

50 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { ReactNode } from "react";
import { accountUsageForUser, agentsLine, getNotifyPrefs, isSuperadmin, pendingFeedbackCount } from "@peppa/core";
import { db } from "@/lib/db";
import { subscriptionRequestOffers } from "@peppa/runner";
import { requireUser, uiMode } from "@/lib/auth";
import { navCounts } from "@/lib/queries";
import { WordsProvider } from "@/components/Words";
import { Sidebar } from "@/components/Sidebar";
import { AttentionBadge } from "@/components/AttentionBadge";
import { CommandPalette } from "@/components/CommandPalette";
import { AgentsStrip, UsageStrip } from "@/components/Accounting";
import { VersionWatch } from "@/components/VersionWatch";
import { bootId } from "@/lib/boot";
import { FeedbackButton } from "@/components/FeedbackButton";
export const dynamic = "force-dynamic";
/** Console layout (PEP-38): navigation on the left, each page renders centre + right panel via <Workspace>. */
export default async function AppLayout({ children }: { children: ReactNode }) {
const user = await requireUser();
// PEP-216: independent reads together, not one after another on every page.
const [counts, { sound }, superadmin, mode] = await Promise.all([navCounts(user.id), getNotifyPrefs(db, user.id), isSuperadmin(db, user), uiMode()]);
const engineer = mode === "engineer";
// PEP-5: subscription limit windows over every page — for «Инженер»; PEP-121: «Продакт»
// reads one line: agents work, or when they go on.
const [accounts, line, feedback] = await Promise.all([
engineer ? accountUsageForUser(db, user).catch(() => []) : [],
engineer ? null : agentsLine(db, user).catch(() => ({ state: "working" as const })),
superadmin ? pendingFeedbackCount(db) : 0,
]);
// PEP-186: agents stand — the owner may ask the superadmin for a subscription right from the strip.
const offers = line?.state === "paused" ? await subscriptionRequestOffers(db, user).catch(() => []) : [];
return (
<WordsProvider mode={mode}>
<div className="min-h-dvh md:grid md:grid-cols-[232px_minmax(0,1fr)]">
<AttentionBadge count={counts.questions + counts.waitingRunners} sound={sound} />
<Sidebar login={user.login} avatarUrl={user.avatarUrl} counts={{ ...counts, feedback }} superadmin={superadmin} engineer={engineer} />
<div className="flex min-w-0 flex-col pb-16 md:pb-0">
<VersionWatch boot={bootId()} />
{line ? <AgentsStrip line={line} offers={offers} /> : <UsageStrip accounts={accounts} admin={superadmin} />}
{children}
</div>
<CommandPalette />
{/* PEP-143: «Сообщить о проблеме» on every page. */}
<FeedbackButton />
</div>
</WordsProvider>
);
}