Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/controller/cve-id.controller/cve-id.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ async function getFilteredCveId (req, res, next) {
const requesterOrgUUID = await authContext.getRequesterOrgUUID(req, orgRepo)

// Create map of orgUUID to shortnames and users to simplify aggregation later
const orgs = await orgRepo.getAllOrgs()
const users = await userRepo.getAllUsers()
// Only project the fields needed for the maps to avoid fetching full documents
const orgs = await orgRepo.getAllOrgs({}, { UUID: 1, short_name: 1, _id: 0 })
const users = await userRepo.getAllUsers({}, { UUID: 1, username: 1, org_UUID: 1, _id: 0 })

const orgMap = {}
const userMap = {}
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/orgRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class OrgRepository extends BaseRepository {
return utils.isBulkDownload(shortName)
}

async getAllOrgs () {
return this.collection.find()
async getAllOrgs (options = {}, projection = {}) {
return this.collection.find({}, projection, options)
}

async deleteOneByShortName (shortName, options = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/userRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class UserRepository extends BaseRepository {
return this.collection.findOneAndUpdate(filter, updatePayload, options)
}

async getAllUsers () {
return this.collection.find()
async getAllUsers (options = {}, projection = {}) {
return this.collection.find({}, projection, options)
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/unit-tests/cve-id/cveIdGetAllTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ describe('Testing getFilteredCveId function', () => {
expect(cveIdRepo.aggregatePaginate.args[0][0][0].$match).to.deep.equal(builtQuery)
})

it('Should request only the fields needed to build the org and user maps', async () => {
await cveIdController.CVEID_GET_FILTER(req, res, next)
expect(orgRepo.getAllOrgs.calledOnceWith({}, { UUID: 1, short_name: 1, _id: 0 })).to.equal(true)
expect(userRepo.getAllUsers.calledOnceWith({}, { UUID: 1, username: 1, org_UUID: 1, _id: 0 })).to.equal(true)
})

it('Should swap UUIDs for names in Cve-ids', async () => {
await cveIdController.CVEID_GET_FILTER(req, res, next)
expect(res.status.args[0][0]).to.equal(200)
Expand Down
Loading