From 040e56b0043c5c2bb228f598c1b786f06a59f679 Mon Sep 17 00:00:00 2001 From: "Ruben D." Date: Mon, 6 Jan 2025 17:15:11 +0100 Subject: [PATCH] concurrent requests for acl and meta resources on list all --- src/commands/solid-list.ts | 34 +++++++++++++++++++++------------- src/commands/solid-perms.ts | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/commands/solid-list.ts b/src/commands/solid-list.ts index 61109d2..c3b7115 100644 --- a/src/commands/solid-list.ts +++ b/src/commands/solid-list.ts @@ -30,21 +30,29 @@ export default async function list(url: string, options?: ICommandOptionsList) { if(resourceInfo) resourceInfos.push(resourceInfo) } } - + const promiseList: Promise[] = []; for (let containedResourceUrl of containedResources) { - let resourceInfo = getResourceInfoFromDataset(dataset, containedResourceUrl, url); - if (resourceInfo && !resourceInfo.isDir && commandOptions.all) { // We only want to show acl files in the current dir. Aka the ones of the current dir + the ones of contained files - const headerResources = await getAclAndMetadata(containedResourceUrl, url, commandOptions.fetch) - if (headerResources.acl) { - resourceInfo.acl = headerResources.acl - resourceInfos.push(headerResources.acl) - } - if (headerResources.meta) { - resourceInfo.metadata = headerResources.meta - resourceInfos.push(headerResources.meta) + promiseList.push(new Promise((resolve, reject) => { + let resourceInfo = getResourceInfoFromDataset(dataset, containedResourceUrl, url); + if (resourceInfo && !resourceInfo.isDir && commandOptions.all) { // We only want to show acl files in the current dir. Aka the ones of the current dir + the ones of contained files + getAclAndMetadata(containedResourceUrl, url, commandOptions.fetch) + .then((headerResources) => { + if (headerResources.acl) resourceInfo.acl = headerResources.acl + if (headerResources.meta) resourceInfo.metadata = headerResources.meta + resolve(resourceInfo); + }) + } else { + resolve(resourceInfo); } - } - if (resourceInfo) resourceInfos.push(resourceInfo) + })) } + + const metadataResourceInfoList = (await Promise.all(promiseList)).filter((e) => !!e) + resourceInfos = resourceInfos.concat(metadataResourceInfoList) + metadataResourceInfoList.forEach( (resourceInfo: ResourceInfo) => { + if(resourceInfo.acl) resourceInfos.push(resourceInfo.acl) + if(resourceInfo.metadata) resourceInfos.push(resourceInfo.metadata) + }); return resourceInfos + } diff --git a/src/commands/solid-perms.ts b/src/commands/solid-perms.ts index 91a847b..b56d7b3 100644 --- a/src/commands/solid-perms.ts +++ b/src/commands/solid-perms.ts @@ -45,6 +45,7 @@ export async function listPermissions(resourceUrl: string, options?: ICommandOpt try { permissions.access.agent = await universalAccess.getAgentAccessAll(resourceUrl, {fetch: commandOptions.fetch}) permissions.access.public = await universalAccess.getPublicAccess(resourceUrl, {fetch: commandOptions.fetch}) + console.log('PERMISSIONS', permissions) return permissions } catch (e) { if (commandOptions.verbose) writeErrorString(`Could not retrieve permissions for ${resourceUrl}`, e, commandOptions)