summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-09-05 17:10:57 +0200
committerJames Lopez <james@jameslopez.es>2017-09-05 17:47:45 +0200
commit4119206f76d802413850dc9fe1fa4715c3bd6fc0 (patch)
tree01877dafda4888e318bdafa85df23973836818bc
parentbe99f82478e023e41a543a0b9348e27d56fb3c13 (diff)
downloadgitlab-ce-4119206f76d802413850dc9fe1fa4715c3bd6fc0.tar.gz
fix export performance of CI builds
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--lib/gitlab/import_export/import_export.yml1
-rw-r--r--lib/gitlab/import_export/reader.rb4
-rw-r--r--spec/lib/gitlab/import_export/project_tree_saver_spec.rb19
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')