Skip to content

Commit 77e78cc

Browse files
committed
fix: Only re-read the query if its path or frontmatter has changed
1 parent c52de8b commit 77e78cc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Renderer/QueryRenderer.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ class QueryRenderChild extends MarkdownRenderChild {
128128
}
129129

130130
// TODO We need to debounce this.
131-
// TODO This very primitive first version redraws all queries for *every* edit to the file containing
132-
// this query, regardless of whether the frontmatter has changed or not.
133-
// TODO It may even create duplicate refreshes when the query itself is edited
134-
// TODO Only do this if the metadata has changed - as this also gets called when the note body is changed.
135131
this.handleMetadataOrFilePathChange(filePath, fileCache);
136132
}),
137133
);
@@ -148,9 +144,18 @@ class QueryRenderChild extends MarkdownRenderChild {
148144
}
149145

150146
private handleMetadataOrFilePathChange(filePath: string, fileCache: CachedMetadata | null) {
147+
const oldTasksFile = this.queryResultsRenderer.tasksFile;
151148
const newTasksFile = new TasksFile(filePath, fileCache ?? {});
152-
this.queryResultsRenderer.setTasksFile(newTasksFile);
153-
this.events.triggerRequestCacheUpdate(this.render.bind(this));
149+
150+
// Has anything changed which might change the query results?
151+
const differentPath = oldTasksFile.path !== newTasksFile.path;
152+
const differentFrontmatter = !oldTasksFile.rawFrontmatterIdenticalTo(newTasksFile);
153+
const queryNeedsReloading = differentPath || differentFrontmatter;
154+
155+
if (queryNeedsReloading) {
156+
this.queryResultsRenderer.setTasksFile(newTasksFile);
157+
this.events.triggerRequestCacheUpdate(this.render.bind(this));
158+
}
154159
}
155160

156161
onunload() {

0 commit comments

Comments
 (0)