From 9fa0bbc834ba4a95a946e033b31bdb01e0101573 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:51:50 +0000 Subject: [PATCH] perf: optimize seo-audit.mjs with parallel async file reading Refactors the main file reading loop in `seo-audit.mjs` to use `readFile` from `node:fs/promises` and `Promise.all` instead of the synchronous `readFileSync`. This parallelizes disk I/O when processing large numbers of generated HTML files. Co-authored-by: lsb11 <269203137+lsb11@users.noreply.github.com> --- .gitignore | 1 + seo-audit.mjs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 75f4737..88b54aa 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ gsc-coverage-report.csv .seo-fix-backup-path service_account.json +dist_large/ diff --git a/seo-audit.mjs b/seo-audit.mjs index 5daacec..1f94fc3 100644 --- a/seo-audit.mjs +++ b/seo-audit.mjs @@ -2,6 +2,7 @@ // seo-audit.mjs — machine-check every built page in dist/. // Run after `npm run build`. Exits 1 if any ERROR found (CI-safe). import { readdirSync, readFileSync, existsSync, statSync } from 'node:fs'; +import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; const DIST = 'dist'; @@ -68,9 +69,9 @@ const titles = new Map(); const descs = new Map(); const NOINDEX_OK = [/^\/404(\.html)?\/?$/, /^\/sitemap-page\/$/, /^\/embed\//]; -for (const f of htmlFiles) { +await Promise.all(htmlFiles.map(async (f) => { const page = f.slice(DIST.length).replace(/index\.html$/, '') || '/'; - const html = readFileSync(f, 'utf8'); + const html = await readFile(f, 'utf8'); const isNoindexOk = NOINDEX_OK.some((r) => r.test(page)) || page === '/404.html/'; // canonical @@ -132,7 +133,7 @@ for (const f of htmlFiles) { else if (r === 'needs-slash') warn(`${page} — link ${h} missing trailing slash (301 hop)`); else if (r === 'redirect' && !h.startsWith('/go/')) warn(`${page} — link ${h} goes through a 301 (point it at the target directly)`); } -} +})); // duplicates for (const [t, pages] of titles) if (pages.length > 1) warn(`DUPLICATE TITLE on ${pages.join(' , ')} :: "${t.slice(0, 70)}"`);