fix(createCollectionsForAllMembers): skip existing collections, fix N+1 API calls, fix unlock branch - #48
Open
mosulcoder wants to merge 1 commit into
Conversation
…+1 calls, fix unlock branch - Skip instead of update: when a collection already exists inside the parent collection for a member, the script now logs a message and moves on to the next member rather than updating it - Eliminate N+1 API calls: fetch all org-collections once before the loop and filter in-memory with jq, instead of calling bw list org-collections once per member (~4s x N wasted API calls per run) - Fix broken unlock branch: remove the if/else unlock block where the 'already unlocked' else branch called bw unlock without providing credentials (would hang on stdin). Always supply password via printf; bw unlock is idempotent - Switch loop to process substitution: change 'echo | while read' to 'while read; done < <(...)' so the loop runs in the current shell, fixing counter variable scoping and set -e reliability - Add bw sync before fetching to ensure the CLI cache is fresh - Remove unused curl from dependency check - Add empty member name fallback to member ID - Add created/skipped summary count at end of run
fer
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR improves
createCollectionsForAllMembers.shwith several reliability and performance fixes.Behavior change: skip existing collections instead of updating
Previously, when a collection already existed for a member (matched by
externalId), the script would update its name. This PR changes that behavior: if a collection with the matching name already exists inside the parent collection, the script skips that member and moves on to the next one.Performance: eliminate N+1 API calls
The previous script called
bw list org-collectionsonce per member inside the loop. With ~10 members that was ~10 redundant API calls (~4s each), adding ~40s of unnecessary wait time per run.The collection list is now fetched once before the loop and filtered in-memory with
jq.Fix: broken unlock branch
The previous unlock logic had an inverted condition where the
elsebranch (triggered when the vault was already unlocked) calledbw unlock --rawwithout supplying credentials, which would hang waiting for stdin. Both paths now consistently useprintf "%s" "$password" | bw unlock --raw(which is idempotent).Additional improvements
echo | while readpipeline to process substitutionwhile read; done < <(...)so counters andset -ebehave correctlybw syncbefore fetching to ensure the CLI cache is freshcurlfrom the dependency check (it was listed but never called)Created: X | Skipped (already existed): Y