perf: build git last-modified map in one pass instead of per-file (#837)

Replace ~314 `git log` spawns per gen script with a single `git log --name-only` pass, memoised per process. Cuts gen:last-updated + gen:sitemap from ~15s to ~1.5s.

Output is byte-identical to the per-file version; still degrades to no-dates when git is unavailable (e.g. the Docker image).
This commit is contained in:
Jack Carter
2026-07-09 11:19:46 +02:00
committed by GitHub
parent 25898dced9
commit e7b2214883
3 changed files with 53 additions and 4 deletions
+3 -2
View File
@@ -13,7 +13,7 @@
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { getGitLastModified } from './git-dates.mjs'
import { buildGitDateMap } from './git-dates.mjs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const ROOT = path.join(__dirname, '..')
@@ -45,9 +45,10 @@ const entries = findMdxRoutes(PAGES_DIR)
.filter((r) => r.route !== '/' && r.route !== '')
.sort((a, b) => a.route.localeCompare(b.route))
const gitDates = buildGitDateMap()
const map = {}
for (const { route, filePath } of entries) {
const date = getGitLastModified(filePath)
const date = gitDates.get(path.relative(ROOT, filePath))
if (date) map[route] = date
}