From 3d8c0a4a10a6776e06235baeac10f33d6b3905dd Mon Sep 17 00:00:00 2001 From: Paul de Raaij Date: Tue, 12 Nov 2024 20:17:43 +0100 Subject: [PATCH] Stop iterating over all resources for finding matching identifiers --- 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,