Commit 079c55f3 authored by Sean McGivern's avatar Sean McGivern

Fix N+1 for CI artifacts in MR widget

This is a little more subtle: the more matching artifacts there are, the more
queries we'd run.
parent 0c8e707b
...@@ -18,40 +18,40 @@ module EE ...@@ -18,40 +18,40 @@ module EE
# codeclimate_artifact is deprecated and replaced with code_quality_artifact (#5779) # codeclimate_artifact is deprecated and replaced with code_quality_artifact (#5779)
def codeclimate_artifact def codeclimate_artifact
@codeclimate_artifact ||= artifacts.find(&:has_codeclimate_json?) @codeclimate_artifact ||= artifacts_with_files.find(&:has_codeclimate_json?)
end end
def code_quality_artifact def code_quality_artifact
@code_quality_artifact ||= artifacts.find(&:has_code_quality_json?) @code_quality_artifact ||= artifacts_with_files.find(&:has_code_quality_json?)
end end
def performance_artifact def performance_artifact
@performance_artifact ||= artifacts.find(&:has_performance_json?) @performance_artifact ||= artifacts_with_files.find(&:has_performance_json?)
end end
def sast_artifact def sast_artifact
@sast_artifact ||= artifacts.find(&:has_sast_json?) @sast_artifact ||= artifacts_with_files.find(&:has_sast_json?)
end end
def dependency_scanning_artifact def dependency_scanning_artifact
@dependency_scanning_artifact ||= artifacts.find(&:has_dependency_scanning_json?) @dependency_scanning_artifact ||= artifacts_with_files.find(&:has_dependency_scanning_json?)
end end
def license_management_artifact def license_management_artifact
@license_management_artifact ||= artifacts.find(&:has_license_management_json?) @license_management_artifact ||= artifacts_with_files.find(&:has_license_management_json?)
end end
# sast_container_artifact is deprecated and replaced with container_scanning_artifact (#5778) # sast_container_artifact is deprecated and replaced with container_scanning_artifact (#5778)
def sast_container_artifact def sast_container_artifact
@sast_container_artifact ||= artifacts.find(&:has_sast_container_json?) @sast_container_artifact ||= artifacts_with_files.find(&:has_sast_container_json?)
end end
def container_scanning_artifact def container_scanning_artifact
@container_scanning_artifact ||= artifacts.find(&:has_container_scanning_json?) @container_scanning_artifact ||= artifacts_with_files.find(&:has_container_scanning_json?)
end end
def dast_artifact def dast_artifact
@dast_artifact ||= artifacts.find(&:has_dast_json?) @dast_artifact ||= artifacts_with_files.find(&:has_dast_json?)
end end
def initialize_yaml_processor def initialize_yaml_processor
...@@ -148,6 +148,12 @@ module EE ...@@ -148,6 +148,12 @@ module EE
def expose_code_quality_data? def expose_code_quality_data?
has_code_quality_data? has_code_quality_data?
end end
private
def artifacts_with_files
@artifacts_with_files ||= artifacts.includes(:job_artifacts_metadata, :job_artifacts_archive).to_a
end
end end
end end
end end
...@@ -173,18 +173,23 @@ describe Ci::Pipeline do ...@@ -173,18 +173,23 @@ describe Ci::Pipeline do
end end
context 'performance' do context 'performance' do
def create_build(job_name) def create_build(job_name, filename)
create( create(
:ci_build, :ci_build,
:artifacts, :artifacts,
name: job_name, name: job_name,
pipeline: pipeline pipeline: pipeline,
options: {
artifacts: {
paths: [filename]
}
}
) )
end end
it 'does not perform extra queries when calling pipeline artifacts methods after the first' do it 'does not perform extra queries when calling pipeline artifacts methods after the first' do
create_build('codeclimate') create_build('codeclimate', 'codeclimate.json')
create_build('dependency_scanning') create_build('dependency_scanning', 'gl-dependency-scanning-report.json')
pipeline.code_quality_artifact pipeline.code_quality_artifact
......
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