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