Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3397 #3421

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Template extends TemplateContent {

if (types.data) {
delete this._dataCache;
// delete this._usePermalinkRoot;
// delete this._stats;
}

if (types.render) {
Expand Down Expand Up @@ -264,6 +266,7 @@ class Template extends TemplateContent {
}

async usePermalinkRoot() {
// @cachedproperty
if (this._usePermalinkRoot === undefined) {
// TODO this only works with immediate front matter and not data files
let { data } = await this.getFrontMatterData();
Expand Down Expand Up @@ -394,8 +397,10 @@ class Template extends TemplateContent {

async getData() {
if (!this._dataCache) {
// @cachedproperty
this._dataCache = this.#getData();
}

return this._dataCache;
}

Expand Down Expand Up @@ -441,6 +446,7 @@ class Template extends TemplateContent {

// This is the primary render mechanism, called via TemplateMap->populateContentDataInMap
async renderPageEntryWithoutLayout(pageEntry) {
// @cachedproperty
if (!this._cacheRenderedPromise) {
this._cacheRenderedPromise = this.renderDirect(pageEntry.rawInput, pageEntry.data);
this.renderCount++;
Expand Down Expand Up @@ -858,7 +864,7 @@ class Template extends TemplateContent {
}

async renderPageEntry(pageEntry) {
// cache with transforms output
// @cachedproperty
if (!pageEntry.template._cacheRenderedTransformsAndLayoutsPromise) {
pageEntry.template._cacheRenderedTransformsAndLayoutsPromise =
this.#renderPageEntryWithLayoutsAndTransforms(pageEntry);
Expand Down Expand Up @@ -964,6 +970,7 @@ class Template extends TemplateContent {
}

async getInputFileStat() {
// @cachedproperty
if (this._stats) {
return this._stats;
}
Expand Down
5 changes: 3 additions & 2 deletions src/TemplateContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class TemplateContent {
if (types.read) {
delete this.readingPromise;
delete this.inputContent;
delete this.frontMatter;
delete this._frontMatterDataCache;
}
}
Expand Down Expand Up @@ -235,10 +234,11 @@ class TemplateContent {
async read() {
if (!this.readingPromise) {
if (!this.inputContent) {
// cache the promise
// @cachedproperty
this.inputContent = this.getInputContent();
}

// @cachedproperty
this.readingPromise = this.#read();
}

Expand Down Expand Up @@ -355,6 +355,7 @@ class TemplateContent {

async getFrontMatterData() {
if (!this._frontMatterDataCache) {
// @cachedproperty
this._frontMatterDataCache = this.#getFrontMatterData();
}

Expand Down
9 changes: 7 additions & 2 deletions src/TemplateWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class TemplateWriter {
};
}

// incrementalFileShape is `template` or `copy` (for passthrough file copy)
async _addToTemplateMapIncrementalBuild(incrementalFileShape, paths, to = "fs") {
// Render overrides are only used when `--ignore-initial` is in play and an initial build is not run
let ignoreInitialBuild = !this.isRunInitialBuild;
Expand All @@ -197,6 +198,11 @@ class TemplateWriter {

templates.push(tmpl);

// This must happen before data is generated for the incremental file only
if (incrementalFileShape === "template" && tmpl.inputPath === this.incrementalFile) {
tmpl.resetCaches();
}

// IMPORTANT: This is where the data is first generated for the template
promises.push(this.templateMap.add(tmpl));
}
Expand Down Expand Up @@ -254,8 +260,7 @@ class TemplateWriter {
// Order of templates does not matter here, they’re reordered later based on dependencies in TemplateMap.js
for (let tmpl of templates) {
if (incrementalFileShape === "template" && tmpl.inputPath === this.incrementalFile) {
tmpl.resetCaches();

// Cache is reset above (to invalidate data cache at the right time)
tmpl.setDryRunViaIncremental(false);
} else if (!tmpl.isRenderableDisabled() && !tmpl.isRenderableOptional()) {
// Related to the template but not the template (reset the render cache, not the read cache)
Expand Down