diff --git a/app/models/project.rb b/app/models/project.rb index 7d6f7fd2c581325dc4b0dfa268d37a4e5568448e..4039af7a330f719a09936ed4258041c75944a7d4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1378,6 +1378,7 @@ class Project < ActiveRecord::Base repository.raw_repository.write_ref('HEAD', "refs/heads/#{branch}") repository.copy_gitattributes(branch) repository.after_change_head + ProjectCacheWorker.perform_async(self.id, [], [:commit_count]) reload_default_branch else errors.add(:base, "Could not change HEAD: branch '#{branch}' does not exist") diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb index d27b5e625743f8fabca74b2e88fca86e5c44034a..b31099bc67058071f1d7ab80113e5043c03353ca 100644 --- a/app/workers/project_cache_worker.rb +++ b/app/workers/project_cache_worker.rb @@ -27,6 +27,7 @@ class ProjectCacheWorker # rubocop: enable CodeReuse/ActiveRecord def update_statistics(project, statistics = []) + return if Gitlab::Database.read_only? return unless try_obtain_lease_for(project.id, :update_statistics) Rails.logger.info("Updating statistics for project #{project.id}") diff --git a/changelogs/unreleased/refresh-commit-count-after-head-change.yml b/changelogs/unreleased/refresh-commit-count-after-head-change.yml new file mode 100644 index 0000000000000000000000000000000000000000..27e278958b871f69b28dced8f8b969f2325d900c --- /dev/null +++ b/changelogs/unreleased/refresh-commit-count-after-head-change.yml @@ -0,0 +1,5 @@ +--- +title: Refresh commit count after repository head changes +merge_request: 26473 +author: +type: fixed diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 71bd7972436717fed125b023abcfbb6cbffdabef..3beddaeddbdc3f5fcb7e2d4e51e895a176d663c9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2388,6 +2388,12 @@ describe Project do project.change_head(project.default_branch) end + it 'updates commit count' do + expect(ProjectCacheWorker).to receive(:perform_async).with(project.id, [], [:commit_count]) + + project.change_head(project.default_branch) + end + it 'copies the gitattributes' do expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch) project.change_head(project.default_branch)