Commit b9c19f6b authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Filipa Lacerda

Do not serialize a pipeline again when showing a build

This change makes it possible to avoid additional serialization of
entire pipeline when rendering a build details page. Instead we expose
more information from the build entity itself what is much cheaper than
serializing entire pipeline.

Additionally we do not need to serialize `latest?` flag, which involves
multiple Gitaly calls.
parent 819746dc
......@@ -184,16 +184,9 @@ export const receiveTraceError = ({ commit }) => {
export const requestStages = ({ commit }) => commit(types.REQUEST_STAGES);
export const fetchStages = ({ state, dispatch }) => {
dispatch('requestStages');
axios
.get(`${state.job.pipeline_path}.json`)
.then(({ data }) => {
// Set selected stage
dispatch('receiveStagesSuccess', data.details.stages);
const selectedStage = data.details.stages.find(stage => stage.name === state.selectedStage);
dispatch('fetchJobsForStage', selectedStage);
})
.catch(() => dispatch('receiveStagesError'));
dispatch('receiveStagesSuccess', state.job.pipeline.details.stages);
const selectedStage = state.job.pipeline.details.stages.find(stage => stage.name === state.selectedStage);
dispatch('fetchJobsForStage', selectedStage);
};
export const receiveStagesSuccess = ({ commit }, data) =>
commit(types.RECEIVE_STAGES_SUCCESS, data);
......
......@@ -8,11 +8,8 @@ class BuildDetailsEntity < JobEntity
expose :stuck?, as: :stuck
expose :user, using: UserEntity
expose :runner, using: RunnerEntity
# expose :pipeline, using: PipelineEntity
expose :pipeline_path do |build|
project_pipeline_path(build.project, build.pipeline)
end
expose :metadata, using: BuildMetadataEntity
expose :pipeline, using: PipelineEntity
expose :deployment_status, if: -> (*) { build.starts_environment? } do
expose :deployment_status, as: :status
......@@ -20,8 +17,6 @@ class BuildDetailsEntity < JobEntity
expose :persisted_environment, as: :environment, with: EnvironmentEntity
end
expose :metadata, using: BuildMetadataEntity
expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do
expose :download_path, if: -> (*) { build.artifacts? } do |build|
download_project_job_artifacts_path(project, build)
......
# frozen_string_literal: true
class PipelineDetailsEntity < PipelineEntity
expose :flags do
expose :latest?, as: :latest
end
expose :details do
expose :ordered_stages, as: :stages, using: StageEntity
expose :artifacts, using: BuildArtifactEntity
expose :manual_actions, using: BuildActionEntity
expose :scheduled_actions, using: BuildActionEntity
......
......@@ -20,7 +20,6 @@ class PipelineEntity < Grape::Entity
end
expose :flags do
expose :latest?, as: :latest
expose :stuck?, as: :stuck
expose :auto_devops_source?, as: :auto_devops
expose :merge_request_event?, as: :merge_request
......@@ -34,6 +33,7 @@ class PipelineEntity < Grape::Entity
expose :details do
expose :detailed_status, as: :status, with: DetailedStatusEntity
expose :ordered_stages, as: :stages, using: StageEntity
expose :duration
expose :finished_at
end
......
......@@ -48,8 +48,8 @@ describe PipelineEntity do
it 'contains flags' do
expect(subject).to include :flags
expect(subject[:flags])
.to include :latest, :stuck, :auto_devops,
:yaml_errors, :retryable, :cancelable, :merge_request
.to include :stuck, :auto_devops, :yaml_errors,
:retryable, :cancelable, :merge_request
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