Resolves issue #1843, Use field projections in getFilteredCveId.#1916
Resolves issue #1843, Use field projections in getFilteredCveId.#1916ChenyangLi4288 wants to merge 4 commits into
Conversation
…edCveId Add optional projection parameters to OrgRepository.getAllOrgs and UserRepository.getAllUsers so callers can limit returned fields. getFilteredCveId now fetches only UUID and short_name for orgs, and UUID, username, and org_UUID for users, instead of entire documents.
|
Hey @ChenyangLi4288, thank you for your contribution. In general, this looks good, however, if you could please do the following: Add unit coverage that asserts the projections are actually passed: Thanks! |
Thank you for your review! @david-rocca! Added a test to ensure they got called. |
Closes Issue #1843
Summary
getFilteredCveIdpreviously fetched the entire Org and User collections just to build UUID-to-name lookup maps, which can be slow and memory-heavy on large deployments. This PR adds optional projection parameters toOrgRepository.getAllOrgsandUserRepository.getAllUsersso callers can limit returned fields.getFilteredCveIdnow fetches onlyUUIDandshort_namefor orgs, andUUID,username, andorg_UUIDfor users, instead of entire documents.Important Changes
src/repositories/orgRepository.jsgetAllOrgsnow accepts optionaloptionsandprojectionparameters and passes them tocollection.find(). Defaults preserve existing behavior.src/repositories/userRepository.jsgetAllUsersnow accepts optionaloptionsandprojectionparameters and passes them tocollection.find(). Defaults preserve existing behavior.src/controller/cve-id.controller/cve-id.controller.jsgetFilteredCveIdpasses field projections:{ UUID: 1, short_name: 1, _id: 0 }for orgs and{ UUID: 1, username: 1, org_UUID: 1, _id: 0 }for users.Testing
Steps to manually test updated functionality, if possible
npm run action:test); all 337 tests pass, including thegetFilteredCveIdtests covering query building and UUID-to-name swapping.GET /api/cve-idas a CNA user and as the secretariat, and confirm the response (includingrequested_byorg short names and usernames) is unchanged from before this PR.Notes
UUIDandusernamefor users, but the map-building code also readsuser.org_UUIDto group users under their org soorg_UUIDis included in the projection as well.