From d26727b1dd63d4994266c6ff55836bc477e2e9d4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 01:25:02 +0000 Subject: [PATCH] Optimize dashboard render performance by computing portfolio metrics once Lifted calculations of portfolio stats and worst-performing domain to the top level of `renderDashboardPage` and passed them down to sub-components `renderDashboardHero` and `renderDashboardStatStrip`. This eliminates redundant O(N) array iterations over the `domains` array during a single dashboard render cycle. Co-authored-by: schmug <38227427+schmug@users.noreply.github.com> --- src/views/dashboard.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/views/dashboard.ts b/src/views/dashboard.ts index 78b10ff..2a59e6c 100644 --- a/src/views/dashboard.ts +++ b/src/views/dashboard.ts @@ -1873,11 +1873,10 @@ function renderOnFireBanner(failing: number): string { } function renderDashboardHero( - domains: DashboardDomain[], + stats: PortfolioStats, + worst: DashboardDomain | null, portfolioTrend: number[], ): string { - const stats = portfolioStats(domains); - const worst = worstDomain(domains); // Mood comes from the worst *graded* domain. With nothing scored yet there // is no signal to react to, so DMarcus defaults to neutral rather than // panicking at a freshly-added entry that just hasn't been scanned. @@ -1978,8 +1977,7 @@ function renderAddDomainWizardShell(): string { `; } -function renderDashboardStatStrip(domains: DashboardDomain[]): string { - const stats = portfolioStats(domains); +function renderDashboardStatStrip(stats: PortfolioStats): string { const totalCard = statCard( "Domains", stats.total, @@ -2040,6 +2038,7 @@ export function renderDashboardPage({ isFirstRun?: boolean; }): string { const stats = portfolioStats(domains); + const worst = worstDomain(domains); const banners: string[] = []; if (plan === "free") banners.push(renderFreeTierBanner()); if (isFirstRun && domains.length === 1) { @@ -2047,11 +2046,8 @@ export function renderDashboardPage({ } if (stats.failing >= 3) banners.push(renderOnFireBanner(stats.failing)); - const hero = - domains.length > 0 - ? renderDashboardHero(domains, portfolioTrend) - : renderDashboardHero([], []); - const statStrip = domains.length > 0 ? renderDashboardStatStrip(domains) : ""; + const hero = renderDashboardHero(stats, worst, portfolioTrend); + const statStrip = domains.length > 0 ? renderDashboardStatStrip(stats) : ""; return dashboardPage( "Domains — dmarc.mx",