From e60abdd6e595a7d8600685600a6838b64634e30e Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 3 Jul 2024 13:41:35 -0500 Subject: [PATCH] Vuln dashboard: Update query to find `Vulnerability` records with no associated `VulnerabilityInstall` records. (#20203) Related to: https://github.com/fleetdm/confidential/issues/7180 Changes: - Updated the `nativeQueryToFindVulnsWithNoAssociatedRecords` query to improve the performance of the update-reports script on large deployments --- ee/vulnerability-dashboard/scripts/update-reports.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ee/vulnerability-dashboard/scripts/update-reports.js b/ee/vulnerability-dashboard/scripts/update-reports.js index 00ecaa23c2..4bea434f4b 100644 --- a/ee/vulnerability-dashboard/scripts/update-reports.js +++ b/ee/vulnerability-dashboard/scripts/update-reports.js @@ -906,12 +906,10 @@ module.exports = { // Check for Vulnerabilities that have no associated Host or VulnerabilityInstall records. let nativeQueryToFindVulnsWithNoAssociatedRecords = - `SELECT id - FROM vulnerability - WHERE id NOT IN ( - SELECT vulnerability - FROM vulnerabilityinstall - );`; + `SELECT v.id + FROM vulnerability v + LEFT JOIN vulnerabilityinstall vi ON v.id = vi.vulnerability + WHERE vi.vulnerability IS NULL;`; let rawResultFromDatabase = await sails.sendNativeQuery(nativeQueryToFindVulnsWithNoAssociatedRecords); let vulnerabilityRecordIdsWithNoAssociatedRecords = rawResultFromDatabase.rows;