From bd21f97973915f350b10afea0185a7aec91d2a4e Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Mon, 3 Jun 2024 14:31:44 -0500 Subject: [PATCH] feat(gql): use wallet for `owner_address` when available for public list commands PE-6232 --- src/commands/list_drive.ts | 16 ++++++++++------ src/commands/list_folder.ts | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/commands/list_drive.ts b/src/commands/list_drive.ts index 2cb5592f..f498b3b4 100644 --- a/src/commands/list_drive.ts +++ b/src/commands/list_drive.ts @@ -42,22 +42,26 @@ new CLICommand({ const rootFolderId = drive.rootFolderId; const withKeys = await parameters.getParameterValue(WithKeysParameter, (value) => !!value); - // We have the drive id from deriving a key, we can derive the owner - const driveOwner = await arDrive.getOwnerForDriveId(driveId); - children = await arDrive.listPrivateFolder({ folderId: rootFolderId, driveKey, maxDepth, includeRoot: true, - owner: driveOwner, + owner: await wallet.getAddress(), withKeys }); } else { const arDrive = cliArDriveAnonymousFactory({ arweave }); - const drive = await arDrive.getPublicDrive({ driveId }); + + // Use wallet for owner if available to improve GQL query performance + const owner = (await (await parameters.getOptionalWallet())?.getAddress()) ?? undefined; + + const drive = await arDrive.getPublicDrive({ + driveId, + owner + }); const rootFolderId = drive.rootFolderId; - children = await arDrive.listPublicFolder({ folderId: rootFolderId, maxDepth, includeRoot: true }); + children = await arDrive.listPublicFolder({ folderId: rootFolderId, maxDepth, includeRoot: true, owner }); } const sortedChildren = children.sort((a, b) => alphabeticalOrder(a.path, b.path)) as ( diff --git a/src/commands/list_folder.ts b/src/commands/list_folder.ts index 729f6bef..fefd98a1 100644 --- a/src/commands/list_folder.ts +++ b/src/commands/list_folder.ts @@ -48,13 +48,21 @@ new CLICommand({ const driveKey = await parameters.getDriveKey({ driveId }); const withKeys = await parameters.getParameterValue(WithKeysParameter, (value) => !!value); - // We have the drive id from deriving a key, we can derive the owner - const driveOwner = await arDrive.getOwnerForDriveId(driveId); - - children = await arDrive.listPrivateFolder({ folderId, driveKey, maxDepth, owner: driveOwner, withKeys }); + children = await arDrive.listPrivateFolder({ + folderId, + driveKey, + maxDepth, + owner: await wallet.getAddress(), + withKeys + }); } else { const arDrive = cliArDriveAnonymousFactory({ arweave }); - children = await arDrive.listPublicFolder({ folderId, maxDepth }); + children = await arDrive.listPublicFolder({ + folderId, + maxDepth, + // Use wallet for owner if available to improve GQL query performance + owner: await (await parameters.getOptionalWallet())?.getAddress() + }); } const sortedChildren = children.sort((a, b) => alphabeticalOrder(a.path, b.path)) as (