#1924 Use direct role lookups instead of broad role scans - #1932
Open
ChenyangLi4288 wants to merge 2 commits into
Open
#1924 Use direct role lookups instead of broad role scans#1932ChenyangLi4288 wants to merge 2 commits into
ChenyangLi4288 wants to merge 2 commits into
Conversation
isSecretariat, isSecretariatUUID, and isBulkDownload previously fetched every org holding the role and compared UUIDs in a loop. Each check is now a single findOne with the role in the query predicate.
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.
Closes Issue #1924
Summary
isSecretariat,isSecretariatUUID, andisBulkDownloadpreviously fetched every org holding the role and compared UUIDs in a loop. Each check is now a singlefindOnewith the role in the query predicate, so role checks are direct indexed lookups instead of unbounded collection scans.Important Changes
src/utils/utils.jsisSecretariatnow runs onefindOneper check with bothshort_nameand the SECRETARIAT role in the query (the registry and legacy branches each queried a single collection, so the two queries collapse safely). Theoptionsobject (e.g. a session) now also applies to the role check.isSecretariatUUIDnow runs a singlefindOneonBaseOrgbyUUID+ role, and returnsfalseearly for a falsy UUID without querying.isBulkDownloadkeeps its legacy short_name -> UUID resolution (the original intentionally mixes the legacyOrgand registryBaseOrgcollections), but the role check is now a directUUID+ rolefindOneinstead of scanning all BULK_DOWNLOAD orgs.UUIDand use lean execution; return semantics are unchanged (missing org, falsy UUID, or role-not-held all still returnfalse).Testing
Verified:
npm run action:test, 337 tests).Organd registryBaseOrgcollections (multi-role secretariat, CNA, BULK_DOWNLOAD, ADP, a legacy-only org, and nonexistent names). All 27 input combinations returned identical results, including edge inputs (null/undefined/""UUIDs) and the legacy-vs-registry divergence case.Notes
findcalls the old implementation used.