Skip to content

Commit

Permalink
batch host record creation
Browse files Browse the repository at this point in the history
  • Loading branch information
eashaw committed Jun 7, 2024
1 parent c5e7b61 commit 27f4b34
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 @@ -383,7 +383,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 @@ -693,7 +696,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 27f4b34

Please sign in to comment.