Commit 67454bc9 authored by scardoso's avatar scardoso

Allow projects and groups to use summary cache

parent d0b6d109
...@@ -23,7 +23,7 @@ module ProjectVulnerabilityFindingsActions ...@@ -23,7 +23,7 @@ module ProjectVulnerabilityFindingsActions
end end
def summary def summary
summary = Gitlab::Vulnerabilities::Summary.new(group, filter_params).findings_counter summary = Gitlab::Vulnerabilities::Summary.new(vulnerable, filter_params).findings_counter
respond_to do |format| respond_to do |format|
format.json do format.json do
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
module Gitlab module Gitlab
module Vulnerabilities module Vulnerabilities
class Summary class Summary
attr_reader :group, :filters attr_reader :vulnerable, :filters
def initialize(group, params) def initialize(vulnerable, params)
@filters = params @filters = params
@group = group @vulnerable = vulnerable
end end
def findings_counter def findings_counter
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
project_ids_to_fetch.each do |project_id| project_ids_to_fetch.each do |project_id|
project_summary = Gitlab::Vulnerabilities::SummaryCache project_summary = Gitlab::Vulnerabilities::SummaryCache
.new(group, project_id) .new(vulnerable, project_id)
.fetch .fetch
summary_keys.each do |key| summary_keys.each do |key|
...@@ -46,11 +46,11 @@ module Gitlab ...@@ -46,11 +46,11 @@ module Gitlab
end end
def found_vulnerabilities def found_vulnerabilities
::Security::VulnerabilityFindingsFinder.new(group, params: filters).execute ::Security::VulnerabilityFindingsFinder.new(vulnerable, params: filters).execute
end end
def use_vulnerability_cache? def use_vulnerability_cache?
Feature.enabled?(:cache_vulnerability_summary, group) && !dynamic_filters_included? Feature.enabled?(:cache_vulnerability_summary, vulnerable) && !dynamic_filters_included?
end end
def dynamic_filters_included? def dynamic_filters_included?
...@@ -60,9 +60,11 @@ module Gitlab ...@@ -60,9 +60,11 @@ module Gitlab
end end
def project_ids_to_fetch def project_ids_to_fetch
return filters[:project_id] if filters.key?('project_id') project_ids = vulnerable.is_a?(Project) ? [vulnerable.id] : []
group.project_ids_with_security_reports return filters[:project_id] + project_ids if filters.key?('project_id')
vulnerable.is_a?(Group) ? vulnerable.project_ids_with_security_reports : project_ids
end end
end end
end end
......
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
module Gitlab module Gitlab
module Vulnerabilities module Vulnerabilities
class SummaryCache class SummaryCache
attr_reader :group, :project_id attr_reader :vulnerable, :project_id
def initialize(group, project_id) def initialize(vulnerable, project_id)
@group = group @vulnerable = vulnerable
@project_id = project_id @project_id = project_id
end end
def fetch(force: false) def fetch(force: false)
Rails.cache.fetch(cache_key, force: force, expires_in: 1.day) do Rails.cache.fetch(cache_key, force: force, expires_in: 1.day) do
findings = ::Security::VulnerabilityFindingsFinder findings = ::Security::VulnerabilityFindingsFinder
.new(group, params: { project_id: [project_id] }) .new(vulnerable, params: { project_id: [project_id] })
.execute(:all) .execute(:all)
.counted_by_severity .counted_by_severity
......
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