Commit aeeffe28 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'invalidate-lm-cache' into 'master'

Invalidate comparison cache when licenses approved or blacklisted

See merge request gitlab-org/gitlab!18960
parents a9e8a9e3 06253747
...@@ -43,4 +43,8 @@ class SoftwareLicensePolicy < ApplicationRecord ...@@ -43,4 +43,8 @@ class SoftwareLicensePolicy < ApplicationRecord
end end
delegate :name, to: :software_license delegate :name, to: :software_license
def self.workaround_cache_key
pluck(:id, :approval_status).flatten
end
end end
...@@ -13,5 +13,11 @@ module Ci ...@@ -13,5 +13,11 @@ module Ci
def get_report(pipeline) def get_report(pipeline)
pipeline&.license_scanning_report pipeline&.license_scanning_report
end end
private
def key(base_pipeline, head_pipeline)
super(base_pipeline, head_pipeline) + project.software_license_policies.workaround_cache_key
end
end end
end end
...@@ -453,6 +453,18 @@ describe MergeRequest do ...@@ -453,6 +453,18 @@ describe MergeRequest do
subject subject
end end
context 'cache key includes sofware license policies' do
let!(:license_1) { create(:software_license_policy, project: project) }
let!(:license_2) { create(:software_license_policy, project: project) }
it 'returns key with license information' do
expect_any_instance_of(Ci::CompareLicenseScanningReportsService)
.to receive(:execute).with(base_pipeline, head_pipeline).and_call_original
expect(subject[:key]).to include(*[license_1.id, license_1.approval_status, license_2.id, license_2.approval_status])
end
end
context 'when cached results is not latest' do context 'when cached results is not latest' do
before do before do
allow_any_instance_of(Ci::CompareLicenseScanningReportsService) allow_any_instance_of(Ci::CompareLicenseScanningReportsService)
......
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