Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulnerability dashboard: batch Host record creation #19595

Merged
merged 2 commits into from
Jun 7, 2024
Merged
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
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
Loading