perf: optimize listing performance #97
Open
+192
−32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, thank you for creating and maintaining this great project! It has been fantastic for us integrating Passbolt into our workflows.
The problem!
When working with several hundred credentials,
passbolt list resourcebecame unusable due to request timeouts.The command would consistently fail with:
Error: Get Resource Getting Resource Secret: Doing Request: Request Context: context deadline exceededRoot Cause
The resource listing implementation suffered from a N+1 query problem:
helper.GetResource()individually for each resource to decrypt fields (N API calls)With 300+ credentials, this resulted in 300+ sequential API calls, exceeding the default context timeout.
The code had a TODO comment acknowledging this performance issue but it had not been addressed yet.
Solution
This PR eliminates the N+1 problem using Passbolt API's existing
contain[secret]parameter to fetch all data in bulk, then decrypt locally:1. Bulk Secret Fetching
ContainSecret: truetoGetResourcesOptionswhen encrypted fields are needed2. Decryption-need detection
--columnflag or CEL filters3. Local Decryption (resource/decrypt.go)
decryptResource()helper usinghelper.GetResourceFromData()4. ResourceType Caching
5. Additional Improvements
--columnflag (previously ignored)"Id"→"ID"for correct ID-based filteringBackward Compatibility
Tested manually to be compatible with Passbolt v3, v4, and v5
Testing
This should make the CLI practical for teams / organizations with loads of credentials. It's especially important for Passbolt v5 where Name, Username, URI, and Description fields are now encrypted in the metadata rather than being available as plaintext.
Looking forward to your feedback!