From a655429fe340d351ff6123bb08f2c388b642b018 Mon Sep 17 00:00:00 2001 From: solvedDev Date: Thu, 8 Sep 2022 14:18:51 +0200 Subject: [PATCH] upd: make loading projects up to 3x faster --- src/components/Projects/ProjectManager.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/Projects/ProjectManager.ts b/src/components/Projects/ProjectManager.ts index 66ff206bd..5e0d13eba 100644 --- a/src/components/Projects/ProjectManager.ts +++ b/src/components/Projects/ProjectManager.ts @@ -96,29 +96,37 @@ export class ProjectManager extends Signal { 'projects', { create: true } ) - const localDirectoryHandle = - await this.app.fileSystem.getDirectoryHandle('~local/projects', { - create: true, - }) const isBridgeFolderSetup = this.app.bridgeFolderSetup.hasFired + const promises = [] + // Load existing projects for await (const handle of directoryHandle.values()) { if (handle.kind !== 'directory') continue - await this.addProject(handle, false, requiresPermissions) + promises.push(this.addProject(handle, false, requiresPermissions)) } if (isBridgeFolderSetup) { + const localDirectoryHandle = + await this.app.fileSystem.getDirectoryHandle( + '~local/projects', + { + create: true, + } + ) + // Load local projects as well for await (const handle of localDirectoryHandle.values()) { if (handle.kind !== 'directory') continue - await this.addProject(handle, false, false) + promises.push(this.addProject(handle, false, false)) } } + await Promise.allSettled(promises) + // Update stored projects if (isBridgeFolderSetup) await this.storeProjects(undefined, true) // Create a placeholder project (virtual project)