From a918fb3f561b2b07b29182ed2b81e7ff6bef0553 Mon Sep 17 00:00:00 2001 From: Peter Heiss Date: Fri, 9 Aug 2024 21:30:33 +0200 Subject: [PATCH] add command for reindex cache --- main.ts | 8 ++++++++ src/settings/VaultTaskCache.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/main.ts b/main.ts index 2d7c826..359a639 100644 --- a/main.ts +++ b/main.ts @@ -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) { diff --git a/src/settings/VaultTaskCache.ts b/src/settings/VaultTaskCache.ts index 32957ee..58617b8 100644 --- a/src/settings/VaultTaskCache.ts +++ b/src/settings/VaultTaskCache.ts @@ -64,6 +64,20 @@ export default class VaultTaskCache { this.changesMade = false; } + async reindex() { + const cache = new Map(); + 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) {