From 4119206f76d802413850dc9fe1fa4715c3bd6fc0 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 5 Sep 2017 17:10:57 +0200 Subject: [PATCH] fix export performance of CI builds --- app/models/ci/build.rb | 4 ++++ lib/gitlab/import_export/import_export.yml | 1 + lib/gitlab/import_export/reader.rb | 4 +--- .../import_export/project_tree_saver_spec.rb | 19 +++++++++++-------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ba3156154ac..6a859af73c3 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -451,6 +451,10 @@ module Ci trace end + def serializable_hash(options = {}) + super(options.merge(when: read_attribute(:when))) + end + private def update_artifacts_size diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml index 78795dd3d92..ec73846d844 100644 --- a/lib/gitlab/import_export/import_export.yml +++ b/lib/gitlab/import_export/import_export.yml @@ -116,6 +116,7 @@ excluded_attributes: statuses: - :trace - :token + - :when push_event_payload: - :event_id diff --git a/lib/gitlab/import_export/reader.rb b/lib/gitlab/import_export/reader.rb index 4f061959047..eb7f5120592 100644 --- a/lib/gitlab/import_export/reader.rb +++ b/lib/gitlab/import_export/reader.rb @@ -18,9 +18,7 @@ module Gitlab attributes = @attributes_finder.find(:project) project_attributes = attributes.is_a?(Hash) ? attributes[:project] : {} - build_hash(@tree).each do |sub_hash| - yield(project_attributes.merge(include: sub_hash)) - end + project_attributes.merge(include: build_hash(@tree)) rescue => e @shared.error(e) false diff --git a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb index 065b0ec6658..82495fe6119 100644 --- a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb @@ -117,6 +117,13 @@ describe Gitlab::ImportExport::ProjectTreeSaver do expect(saved_project_json['pipelines'].first['statuses'].count { |hash| hash['type'] == 'Ci::Build' }).to eq(1) end + it 'builds do not call the attributes for retrieving when' do + allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))) + expect_any_instance_of(Ci::GitlabCiYamlProcessor).not_to receive(:build_attributes) + + saved_project_json + end + it 'has pipeline commits' do expect(saved_project_json['pipelines']).not_to be_empty end @@ -251,15 +258,11 @@ describe Gitlab::ImportExport::ProjectTreeSaver do create(:label_priority, label: group_label, priority: 1) milestone = create(:milestone, project: project) merge_request = create(:merge_request, source_project: project, milestone: milestone) - commit_status = create(:commit_status, project: project) - ci_pipeline = create(:ci_pipeline, - project: project, - sha: merge_request.diff_head_sha, - ref: merge_request.source_branch, - statuses: [commit_status]) + ci_build = create(:ci_build, project: project, when: nil) + ci_build.pipeline.update(project: project) + commit_status = create(:commit_status, project: project, pipeline: ci_build.pipeline) - create(:ci_build, pipeline: ci_pipeline, project: project) create(:milestone, project: project) create(:note, noteable: issue, project: project) create(:note, noteable: merge_request, project: project) @@ -267,7 +270,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do create(:note_on_commit, author: user, project: project, - commit_id: ci_pipeline.sha) + commit_id: ci_build.pipeline.sha) create(:event, :created, target: milestone, project: project, author: user) create(:service, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker') -- GitLab