From 6a4bd341ab7e8b30b270997c2ad680f62dbe0fa1 Mon Sep 17 00:00:00 2001 From: Paul de Raaij Date: Tue, 12 Nov 2024 22:40:52 +0100 Subject: [PATCH] Stop iterating over all resources for finding matching identifiers (#1411) --- packages/foam-vscode/src/core/model/workspace.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/foam-vscode/src/core/model/workspace.ts b/packages/foam-vscode/src/core/model/workspace.ts index 495f859f6..d4becc66c 100644 --- a/packages/foam-vscode/src/core/model/workspace.ts +++ b/packages/foam-vscode/src/core/model/workspace.ts @@ -104,21 +104,19 @@ export class FoamWorkspace implements IDisposable { public getIdentifier(forResource: URI, exclude?: URI[]): string { const amongst = []; const basename = forResource.getBasename(); - for (const res of this._resources.values()) { - // skip elements that cannot possibly match - if (!res.uri.path.endsWith(basename)) { - continue; - } + + this.listByIdentifier(basename).map(res => { // skip self if (res.uri.isEqual(forResource)) { - continue; + return; } + // skip exclude list if (exclude && exclude.find(ex => ex.isEqual(res.uri))) { - continue; + return; } amongst.push(res.uri); - } + }); let identifier = FoamWorkspace.getShortestIdentifier( forResource.path,