-
Notifications
You must be signed in to change notification settings - Fork 420
Description
readInputTargetIndex validates the on-disk index cache by reading the raw _quarto.yml and computing format keys:
quarto-cli/src/project/project-index.ts
Lines 174 to 195 in 5b88d3d
| const formats = (index.projectFormats as string[] | undefined) ?? | |
| Object.keys(index.formats); | |
| const projConfigFile = projectConfigFile(projectDir); | |
| if (!projConfigFile) { | |
| return { index }; | |
| } | |
| let contents = Deno.readTextFileSync(projConfigFile); | |
| if (contents.trim().length === 0) { | |
| contents = kDefaultProjectFileContents; | |
| } | |
| const config = readYamlFromString(contents) as Metadata; | |
| const projFormats = formatKeys(config); | |
| if (ld.isEqual(formats, projFormats)) { | |
| return { | |
| index, | |
| }; | |
| } else { | |
| return { | |
| missingReason: "formats", | |
| }; | |
| } |
It does not resolve metadata-files before computing formatKeys(). When the format: configuration lives in a file referenced by metadata-files (e.g. _website.yml), formatKeys() returns [] while the cached index has the resolved formats (e.g. ["html"]). The comparison always fails, perpetually invalidating the cache.
This forces readBaseInputIndex to run for every project input on every render, even when nothing has changed. For projects with .R spin scripts, this triggers expensive knitr::spin() calls via R on every render.
Repro
Given this _quarto.yml:
project:
type: website
metadata-files:
- _website.ymlAnd _website.yml containing:
website:
title: "test"
navbar:
left:
- href: index.qmd
- about.qmd
format:
html:
theme: [cosmo, brand]
css: styles.css
toc: trueEvery quarto render index.qmd call rebuilds the index for all project inputs, because the cache check reads raw _quarto.yml (no format: key) and mismatches against the cached projectFormats: ["html"].
Moving the format: block into _quarto.yml makes the cache work correctly.
Full repro: https://github.com/byzheng/quarto-metadata-files-test
Context
Root cause of #14225. The effect is most visible when combined with .R spin scripts (each cache miss triggers 3 R process spawns), but the cache invalidation affects all projects using metadata-files for format configuration.