Skip to content

Commit

Permalink
Cyberleague: [premieroctet#159] limit mongo requests if no filter in …
Browse files Browse the repository at this point in the history
…statistics.js
  • Loading branch information
Bastien-Wappizy committed Oct 7, 2024
1 parent 9312a42 commit 153ca4a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions backend/web/server/plugins/cyberleague/statistic.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,25 @@ const increaseValueCount = (data, field, increaseValue) => {

const computeBellwetherStatistics = async (filters) => {
//TODO take filters into account (company sector, region, size)
const companyFilter = {size: {$nin: [COMPANY_SIZE_1001_PLUS, COMPANY_SIZE_0_10]}}
const companyFilter = {}

//Getting scores that will be used to do statistics
const companies = await Company.find(companyFilter)
let scores

const users = await User.find({company: {$in: companies.map((c) => {return c._id})}})
if (companyFilter != {}) {

const scores = await Score.find({creator: {$in: users.map((u) => {return u._id})}}).populate([
{path: 'answers', populate: {path:'answer'}},
{path: 'answers', populate: {path: 'question', $match: {is_bellwether: true}, populate: {path: 'text'}}}
])
const companies = await Company.find(companyFilter)

const users = await User.find({company: {$in: companies.map((c) => {return c._id})}})

scores = await Score.find({creator: {$in: users.map((u) => {return u._id})}}).populate([
{path: 'answers', populate: {path:'answer'}},
{path: 'answers', populate: {path: 'question', $match: {is_bellwether: true}, populate: {path: 'text'}}}
])

} else {
scores = await Score.find()
}

let res = {
securityIncidentManagement: 0,
Expand Down

0 comments on commit 153ca4a

Please sign in to comment.