Skip to content

Commit

Permalink
Vulnerability dashboard: batch Host record creation (#19595)
Browse files Browse the repository at this point in the history
Changes:
- Updated the `update-reports` script to create new host records in
batches.
  • Loading branch information
eashaw authored Jun 7, 2024
1 parent 4b38184 commit bdfcf64
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ee/vulnerability-dashboard/scripts/update-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ module.exports = {
sails.log.warn(`Dry run: ${hostRecordsToUpdate.length} hosts will be updated with new information. (Fleet returned them in the API.)`);
} else {
sails.log(`Creating ${newRecordsForUnrecognizedHosts.length} host records… `);
await Host.createEach(newRecordsForUnrecognizedHosts);
let batchedNewRecordsForUnrecognizedHosts = _.chunk(newRecordsForUnrecognizedHosts, 500);
for(let batch of batchedNewRecordsForUnrecognizedHosts){
await Host.createEach(batch);
}
for(let hostUpdate of hostRecordsToUpdate){
await Host.updateOne({id: hostUpdate.id}).set(_.omit(hostUpdate, 'id'));
}
Expand Down Expand Up @@ -696,7 +699,10 @@ module.exports = {
totalNumberOfHostRecordsCreated += newRecordsForUnrecognizedHosts.length;
totalNumberOfHostRecordsUpdated += hostRecordsToUpdate.length;
sails.log.verbose(`Creating ${newRecordsForUnrecognizedHosts.length} new host records…`);
await Host.createEach(newRecordsForUnrecognizedHosts);
let batchedNewRecordsForUnrecognizedHosts = _.chunk(newRecordsForUnrecognizedHosts, 500);
for(let batch of batchedNewRecordsForUnrecognizedHosts){
await Host.createEach(batch);
}
sails.log.verbose(`Updating ${hostRecordsToUpdate.length} host records…`);
for(let hostUpdate of hostRecordsToUpdate){
await Host.updateOne({id: hostUpdate.id}).set(_.omit(hostUpdate, 'id'));
Expand Down

0 comments on commit bdfcf64

Please sign in to comment.