Skip to content

Commit dbe0bfa

Browse files
committed
Added cache-related commands and skip checking cache for files that will never be cached
1 parent fb72a69 commit dbe0bfa

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

docs/Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Roadmap and Changelog
33
description: Changelog and feature roadmap for Quartz Syncer.
44
created: 2025-05-16T12:59:31Z+0200
5-
modified: 2025-06-15T20:11:55Z+0200
5+
modified: 2025-06-15T21:37:35Z+0200
66
publish: true
77
---
88

main.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,24 @@ export default class QuartzSyncer extends Plugin {
271271
this.togglePublishFlag();
272272
},
273273
});
274+
275+
if (this.settings.useCache) {
276+
this.addCommand({
277+
id: "clear-cache-for-active-file",
278+
name: "Clear cache for active file",
279+
callback: async () => {
280+
await this.clearCacheForActiveFile();
281+
},
282+
});
283+
284+
this.addCommand({
285+
id: "clear-cache-for-all-files",
286+
name: "Clear cache for all files",
287+
callback: async () => {
288+
await this.clearCacheForAllFiles();
289+
},
290+
});
291+
}
274292
}
275293

276294
/**
@@ -294,6 +312,58 @@ export default class QuartzSyncer extends Plugin {
294312
return activeFile;
295313
}
296314

315+
/**
316+
* Clears the cache for the currently active file.
317+
* If no file is active, it does nothing.
318+
*/
319+
async clearCacheForActiveFile() {
320+
const activeFile = this.getActiveFile(this.app.workspace);
321+
322+
if (!activeFile) {
323+
return;
324+
}
325+
326+
const cacheKey = `file:${activeFile.path}`;
327+
328+
if (this.settings.useCache) {
329+
await this.datastore.persister.removeItem(cacheKey);
330+
Logger.info(`Cache cleared for file: ${activeFile.path}`);
331+
new Notice(`Cache cleared for file: ${activeFile.path}`);
332+
} else {
333+
Logger.warn("Cache is disabled, no action taken.");
334+
new Notice("Cache is disabled, no action taken.");
335+
}
336+
}
337+
338+
/**
339+
* Clears the cache for all files.
340+
* This method removes all cached data from the datastore.
341+
* If the cache is disabled, it does nothing.
342+
* It will show a confirmation dialog before clearing the cache.
343+
*/
344+
async clearCacheForAllFiles() {
345+
// Show confirmation dialog before clearing the cache
346+
const confirmation = confirm(
347+
"Are you sure you want to clear the Quartz Syncer cache for all files? This action cannot be undone.",
348+
);
349+
350+
if (!confirmation) {
351+
Logger.info("Cache clearing cancelled by user.");
352+
new Notice("Cache clearing cancelled.");
353+
354+
return;
355+
}
356+
357+
if (this.settings.useCache) {
358+
await this.datastore.recreate();
359+
Logger.info("Cache cleared for all files.");
360+
new Notice("Cache cleared for all files.");
361+
} else {
362+
Logger.warn("Cache is disabled, no action taken.");
363+
new Notice("Cache is disabled, no action taken.");
364+
}
365+
}
366+
297367
/**
298368
* Sets the publication flag value in the frontmatter of the active file.
299369
* If no file is active, it does nothing.

src/publisher/PublishStatusManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default class PublishStatusManager implements IPublishStatusManager {
134134
controller.setText(`Processing ${path}...`);
135135
}
136136

137-
if (!hash || hash !== sha) {
137+
if ((!hash || hash !== sha) && path.endsWith(".md")) {
138138
// Check if file exists in Obsidian vault
139139
if (!this.publisher.vault.getAbstractFileByPath(path)) {
140140
continue;

0 commit comments

Comments
 (0)