Commit 09be5800 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'update_main_lang_if_unset' into 'master'

Only update main language if it is not already set

Related to gitlab-org/gitlab-ce#14937 (but does not fully fix) This is a temporary fix so performance isn't affected so much.

cc @yorickpeterse @ayufan how does this look?

See merge request !3556
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 2ac04162
......@@ -19,6 +19,7 @@ v 8.7.0 (unreleased)
v 8.6.5
- Fix importing from GitHub Enterprise. !3529
- Check permissions when user attempts to import members from another project. !3535
- Only update repository language if it is not set to improve performance. !3556
v 8.6.4
- Don't attempt to fetch any tags from a forked repo (Stan Hu)
......
......@@ -54,12 +54,15 @@ class GitPushService < BaseService
end
def update_main_language
current_language = @project.repository.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?
unless current_language == @project.main_language
return @project.update_attributes(main_language: current_language)
end
return unless is_default_branch?
return unless push_to_new_branch? || push_to_existing_branch?
current_language = @project.repository.main_language
@project.update_attributes(main_language: current_language)
true
end
......
......@@ -165,12 +165,39 @@ 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 }
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
it { expect(@service.update_main_language).to eq(true) }
it { expect(project.main_language).to eq("Ruby") }
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(project.main_language).to eq(nil) }
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