Commit 319dea10 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent cdd95ddd
......@@ -153,6 +153,29 @@ module GitlabRoutingHelper
# Artifacts
# Rails path generators are slow because they need to do large regex comparisons
# against the arguments. We can speed this up 10x by generating the strings directly.
# /*namespace_id/:project_id/-/jobs/:job_id/artifacts/download(.:format)
def fast_download_project_job_artifacts_path(project, job)
expose_fast_artifacts_path(project, job, :download)
end
# /*namespace_id/:project_id/-/jobs/:job_id/artifacts/keep(.:format)
def fast_keep_project_job_artifacts_path(project, job)
expose_fast_artifacts_path(project, job, :keep)
end
# /*namespace_id/:project_id/-/jobs/:job_id/artifacts/browse(/*path)
def fast_browse_project_job_artifacts_path(project, job)
expose_fast_artifacts_path(project, job, :browse)
end
def expose_fast_artifacts_path(project, job, action)
path = "#{project.full_path}/-/jobs/#{job.id}/artifacts/#{action}"
Gitlab::Utils.append_path(Gitlab.config.gitlab.relative_url_root, path)
end
def artifacts_action_path(path, project, build)
action, path_params = path.split('/', 2)
args = [project, build, path_params]
......
......@@ -2,6 +2,7 @@
class BuildArtifactEntity < Grape::Entity
include RequestAwareEntity
include GitlabRoutingHelper
expose :name do |job|
job.name
......@@ -11,15 +12,15 @@ class BuildArtifactEntity < Grape::Entity
expose :artifacts_expire_at, as: :expire_at
expose :path do |job|
download_project_job_artifacts_path(project, job)
fast_download_project_job_artifacts_path(project, job)
end
expose :keep_path, if: -> (*) { job.has_expiring_artifacts? } do |job|
keep_project_job_artifacts_path(project, job)
fast_keep_project_job_artifacts_path(project, job)
end
expose :browse_path do |job|
browse_project_job_artifacts_path(project, job)
fast_browse_project_job_artifacts_path(project, job)
end
private
......
---
title: Speed up path generation with build artifacts
merge_request: 22257
author:
type: performance
......@@ -113,6 +113,29 @@ describe GitlabRoutingHelper do
end
end
context 'artifacts' do
let_it_be(:project) { create(:project) }
let_it_be(:job) { create(:ci_build, project: project, name: 'test:job', artifacts_expire_at: 1.hour.from_now) }
describe '#fast_download_project_job_artifacts_path' do
it 'matches the Rails download path' do
expect(fast_download_project_job_artifacts_path(project, job)).to eq(download_project_job_artifacts_path(project, job))
end
end
describe '#fast_keep_project_job_artifacts_path' do
it 'matches the Rails keep path' do
expect(fast_keep_project_job_artifacts_path(project, job)).to eq(keep_project_job_artifacts_path(project, job))
end
end
describe '#fast_browse_project_job_artifacts_path' do
it 'matches the Rails browse path' do
expect(fast_browse_project_job_artifacts_path(project, job)).to eq(browse_project_job_artifacts_path(project, job))
end
end
end
context 'snippets' do
let_it_be(:personal_snippet) { create(:personal_snippet) }
let_it_be(:project_snippet) { create(:project_snippet) }
......
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