Commit a5eeb6cd authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'sh-optimize-artifact-loading-mr' into 'master'

Optimize query for loading artifacts in pipeline

See merge request gitlab-org/gitlab!62249
parents 27ebaf75 e386fabe
......@@ -660,15 +660,9 @@ module Ci
# Return a hash of file type => array of 1 job artifact
def latest_report_artifacts
::Gitlab::SafeRequestStore.fetch("pipeline:#{self.id}:latest_report_artifacts") do
# Note we use read_attribute(:project_id) to read the project
# ID instead of self.project_id. The latter appears to load
# the Project model. This extra filter doesn't appear to
# affect query plan but included to ensure we don't leak the
# wrong informaiton.
::Ci::JobArtifact.where(
id: job_artifacts.with_reports
.select('max(ci_job_artifacts.id) as id')
.where(project_id: self.read_attribute(:project_id))
.group(:file_type)
)
.preload(:job)
......
---
title: Optimize query for loading artifacts in pipeline
merge_request: 62249
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