From dc590e53d87c77df8dd06c8f99afe6201805acd6 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 30 Aug 2023 15:27:11 +0200 Subject: [PATCH] #642 - Store the search index in a storage file --- CHANGELOG.md | 1 + src/helpers/Extension.ts | 9 ++++++++- src/listeners/dashboard/PagesListener.ts | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20a44a9f..cabf04f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### ⚡️ Optimizations - [#639](https://github.com/estruyf/vscode-front-matter/issues/639): Add check for content type in page folders setting +- [#642](https://github.com/estruyf/vscode-front-matter/issues/642): Store the search index in a storage file ### 🐞 Fixes diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts index 5e061486..9bc4e33d 100644 --- a/src/helpers/Extension.ts +++ b/src/helpers/Extension.ts @@ -331,8 +331,12 @@ export class Extension { let storageUri: Uri | undefined = undefined; if (type === 'global') { storageUri = await this.createGlobalStorageIfNotExists(); + // Clear workspace state + await this.ctx.globalState.update(propKey, undefined); } else { storageUri = await this.createLocalStorageIfNotExists(); + // Clear workspace state + await this.ctx.workspaceState.update(propKey, undefined); } if (storageUri) { @@ -429,7 +433,10 @@ export class Extension { * @returns */ private isFileStorageNeeded(propKey: string) { - return propKey === ExtensionState.Dashboard.Pages.Cache; + return ( + propKey === ExtensionState.Dashboard.Pages.Cache || + propKey === ExtensionState.Dashboard.Pages.Index + ); } /** diff --git a/src/listeners/dashboard/PagesListener.ts b/src/listeners/dashboard/PagesListener.ts index f97837b9..c1c9a899 100644 --- a/src/listeners/dashboard/PagesListener.ts +++ b/src/listeners/dashboard/PagesListener.ts @@ -243,7 +243,7 @@ export class PagesListener extends BaseListener { const pagesIndex = Fuse.createIndex(['title', 'slug', 'description', 'fmBody', 'type'], pages); await Extension.getInstance().setState( ExtensionState.Dashboard.Pages.Index, - pagesIndex, + pagesIndex.toJSON(), 'workspace' ); } @@ -279,7 +279,8 @@ export class PagesListener extends BaseListener { ExtensionState.Dashboard.Pages.Index, 'workspace' ); - const fuse = new Fuse(this.lastPages, fuseOptions, pagesIndex); + const fuseIndex = Fuse.parseIndex(pagesIndex); + const fuse = new Fuse(this.lastPages, fuseOptions, fuseIndex); const results = fuse.search(data.query || ''); const pageResults = results.map((page) => page.item);