summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Blessing <drew@gitlab.com>2016-04-05 17:44:13 -0500
committerDrew Blessing <drew@gitlab.com>2016-04-06 14:56:40 -0500
commit935bf7271d88c8623312004dd6cba791b76503f5 (patch)
tree3463f6b8d1729bf21b96c2b8c8614cf2e5388bea
parent779b9eac57cf45d77e4d62aa1b96e06928daa794 (diff)
downloadgitlab-ce-update_main_lang_if_unset.tar.gz
Only update main language if it is not already setupdate_main_lang_if_unset
-rw-r--r--CHANGELOG1
-rw-r--r--app/services/git_push_service.rb10
-rw-r--r--spec/services/git_push_service_spec.rb26
3 files changed, 27 insertions, 10 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 8db9a9b0d1e..49140eea6c6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -24,6 +24,7 @@ v 8.7.0 (unreleased)
- Build status notifications
v 8.6.5 (unreleased)
+ - Only update repository language if it is not set to improve performance
- Check permissions when user attempts to import members from another project
v 8.6.4
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index 36c9ee92da1..dc74c02760b 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -55,15 +55,15 @@ class GitPushService < BaseService
end
def update_main_language
+ # Performance can be bad so for now only check main_language once
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/14937
+ return if @project.main_language.present?
+
return unless is_default_branch?
return unless push_to_new_branch? || push_to_existing_branch?
current_language = @project.repository.main_language
-
- unless current_language == @project.main_language
- return @project.update_attributes(main_language: current_language)
- end
-
+ @project.update_attributes(main_language: current_language)
true
end
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index 1047e32960e..b40a5c1c818 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -164,21 +164,37 @@ describe GitPushService, services: true do
end
context "after push" do
- before do
- @service = execute_service(project, user, @oldrev, @newrev, ref)
+ def execute
+ execute_service(project, user, @oldrev, @newrev, ref)
end
context "to master" do
let(:ref) { @ref }
- it { expect(@service.update_main_language).to eq(true) }
- it { expect(project.main_language).to eq("Ruby") }
+ context 'when main_language is nil' do
+ it 'obtains the language from the repository' do
+ expect(project.repository).to receive(:main_language)
+ execute
+ end
+
+ it 'sets the project main language' do
+ execute
+ expect(project.main_language).to eq("Ruby")
+ end
+ end
+
+ context 'when main_language is already set' do
+ it 'does not check the repository' do
+ execute # do an initial run to simulate lang being preset
+ expect(project.repository).not_to receive(:main_language)
+ execute
+ end
+ end
end
context "to other branch" do
let(:ref) { 'refs/heads/feature/branch' }
- it { expect(@service.update_main_language).to eq(nil) }
it { expect(project.main_language).to eq(nil) }
end
end