Skip to content

Commit

Permalink
add command for reindex cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiss committed Aug 9, 2024
1 parent 6a71d0d commit a918fb3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export default class VikunjaPlugin extends Plugin {
await this.commands.resetTasksInVikunja();
}
})
this.addCommand({
id: "vikunja-reset-cache",
name: "Reset cache and reindex tasks",
callback: async () => {
await this.cache.reindex();
}

})
}

private async handleEditorChange(data: any) {
Expand Down
14 changes: 14 additions & 0 deletions src/settings/VaultTaskCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ export default class VaultTaskCache {
this.changesMade = false;
}

async reindex() {
const cache = new Map<number, PluginTask>();
const tasks = await this.plugin.processor.getVaultSearcher().getTasks(this.plugin.processor.getTaskParser());
tasks.map(task => {
if (task.task.id === undefined) {
throw new Error("VaultTaskCache: Task id is not defined");
}
cache.set(task.task.id, task);
})
this.cache = cache;
this.changesMade = true;
await this.saveCacheToDisk();
}

updateFileInfos(id: number, filepath: string, lineno: number) {
const cachedTask = this.get(id);
if (cachedTask === undefined) {
Expand Down

0 comments on commit a918fb3

Please sign in to comment.