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