Commit f691ab7b authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'id-reduce-cached-requests' into 'master'

Reduce SQL requests on building artifacts

See merge request gitlab-org/gitlab!58339
parents c2058240 1bd18c81
......@@ -15,18 +15,18 @@ class BuildArtifactEntity < Grape::Entity
expose :path do |artifact|
fast_download_project_job_artifacts_path(
artifact.project,
project,
artifact.job,
file_type: artifact.file_type
)
end
expose :keep_path, if: -> (*) { artifact.expiring? && show_duplicated_paths?(artifact.project) } do |artifact|
fast_keep_project_job_artifacts_path(artifact.project, artifact.job)
expose :keep_path, if: -> (*) { artifact.expiring? && show_duplicated_paths?(project) } do |artifact|
fast_keep_project_job_artifacts_path(project, artifact.job)
end
expose :browse_path, if: -> (*) { show_duplicated_paths?(artifact.project) } do |artifact|
fast_browse_project_job_artifacts_path(artifact.project, artifact.job)
expose :browse_path, if: -> (*) { show_duplicated_paths?(project) } do |artifact|
fast_browse_project_job_artifacts_path(project, artifact.job)
end
private
......@@ -34,4 +34,8 @@ class BuildArtifactEntity < Grape::Entity
def show_duplicated_paths?(project)
!Gitlab::Ci::Features.remove_duplicate_artifact_exposure_paths?(project)
end
def project
options[:project] || artifact.project
end
end
......@@ -28,7 +28,7 @@ class MergeRequests::PipelineEntity < Grape::Entity
rel = rel.select { |artifact| can?(request.current_user, :read_job_artifacts, artifact.job) }
end
BuildArtifactEntity.represent(rel, options)
BuildArtifactEntity.represent(rel, options.merge(project: pipeline.project))
end
expose :detailed_status, as: :status, with: DetailedStatusEntity do |pipeline|
......
......@@ -15,7 +15,7 @@ class PipelineDetailsEntity < Ci::PipelineEntity
rel = rel.select { |artifact| can?(request.current_user, :read_job_artifacts, artifact.job) }
end
BuildArtifactEntity.represent(rel, options)
BuildArtifactEntity.represent(rel, options.merge(project: pipeline.project))
end
expose :manual_actions, using: BuildActionEntity
expose :scheduled_actions, using: BuildActionEntity
......
---
title: Reduce SQL requests on building artifacts
merge_request: 58339
author:
type: performance
......@@ -3,11 +3,13 @@
require 'spec_helper'
RSpec.describe BuildArtifactEntity do
let(:job) { create(:ci_build) }
let(:artifact) { create(:ci_job_artifact, :codequality, expire_at: 1.hour.from_now, job: job) }
let_it_be(:job) { create(:ci_build) }
let_it_be(:artifact) { create(:ci_job_artifact, :codequality, expire_at: 1.hour.from_now, job: job) }
let(:options) { { request: double } }
let(:entity) do
described_class.new(artifact, request: double)
described_class.represent(artifact, options)
end
describe '#as_json' do
......@@ -46,5 +48,15 @@ RSpec.describe BuildArtifactEntity do
expect(subject[:browse_path]).to be_present
end
end
context 'when project is specified in options' do
let(:options) { super().merge(project: job.project) }
it 'doesnt get a project from the artifact' do
expect(artifact).not_to receive(:project)
subject
end
end
end
end
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