Commit 44ae6a12 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '284953-improve-query-for-fetching-vulnerability-scanners' into 'master'

Improve query for fetching vulnerability scanners

See merge request gitlab-org/gitlab!48144
parents 0f3a817c b7bbfcb4
......@@ -18,9 +18,11 @@ module Vulnerabilities
scope :for_projects, -> (project_ids) { where(project_id: project_ids) }
scope :with_report_type, -> do
joins(:findings)
.select('DISTINCT ON ("vulnerability_scanners"."external_id", "vulnerability_occurrences"."report_type") "vulnerability_scanners".*, "vulnerability_occurrences"."report_type" AS "report_type"')
.order('"vulnerability_scanners"."external_id" ASC, "vulnerability_occurrences"."report_type" ASC')
lateral = Vulnerabilities::Finding.where(Vulnerabilities::Finding.arel_table[:scanner_id].eq(arel_table[:id])).select(:report_type).limit(1)
joins("JOIN LATERAL (#{lateral.to_sql}) report_types ON true")
.select('DISTINCT ON ("vulnerability_scanners"."external_id", "report_types"."report_type") "vulnerability_scanners".*, "report_types"."report_type" AS "report_type"')
.order('"vulnerability_scanners"."external_id" ASC, "report_types"."report_type" ASC')
end
end
end
---
title: Improve query for fetching vulnerability scanners
merge_request: 48144
author:
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment