Skip to content

readInputTargetIndex cache validation ignores metadata-files, causing perpetual cache miss #14227

@cderv

Description

@cderv

readInputTargetIndex validates the on-disk index cache by reading the raw _quarto.yml and computing format keys:

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.yml

And _website.yml containing:

website:
  title: "test"
  navbar:
    left:
      - href: index.qmd
      - about.qmd
format:
  html:
    theme: [cosmo, brand]
    css: styles.css
    toc: true

Every 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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions