Omit max-count for diverging_commit_counts behind feature flag
We want to optimize the query for the CountDivergingCommits rpc by removing the --max-count argument now that we have commit graphs enabled for all repositories during housekeeping. However, we want to test this first behind a feature flag.
This commit is contained in:
parent
e1aa7f5074
commit
f86797b5a9
|
@ -283,14 +283,19 @@ class Repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def diverging_commit_counts(branch)
|
def diverging_commit_counts(branch)
|
||||||
|
return diverging_commit_counts_without_max(branch) if Feature.enabled?('gitaly_count_diverging_commits_no_max')
|
||||||
|
|
||||||
|
## TODO: deprecate the below code after 12.0
|
||||||
@root_ref_hash ||= raw_repository.commit(root_ref).id
|
@root_ref_hash ||= raw_repository.commit(root_ref).id
|
||||||
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
|
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
|
||||||
# Rugged seems to throw a `ReferenceError` when given branch_names rather
|
# Rugged seems to throw a `ReferenceError` when given branch_names rather
|
||||||
# than SHA-1 hashes
|
# than SHA-1 hashes
|
||||||
|
branch_sha = branch.dereferenced_target.sha
|
||||||
|
|
||||||
number_commits_behind, number_commits_ahead =
|
number_commits_behind, number_commits_ahead =
|
||||||
raw_repository.diverging_commit_count(
|
raw_repository.diverging_commit_count(
|
||||||
@root_ref_hash,
|
@root_ref_hash,
|
||||||
branch.dereferenced_target.sha,
|
branch_sha,
|
||||||
max_count: MAX_DIVERGING_COUNT)
|
max_count: MAX_DIVERGING_COUNT)
|
||||||
|
|
||||||
if number_commits_behind + number_commits_ahead >= MAX_DIVERGING_COUNT
|
if number_commits_behind + number_commits_ahead >= MAX_DIVERGING_COUNT
|
||||||
|
@ -301,6 +306,22 @@ class Repository
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def diverging_commit_counts_without_max(branch)
|
||||||
|
@root_ref_hash ||= raw_repository.commit(root_ref).id
|
||||||
|
cache.fetch(:"diverging_commit_counts_without_max_#{branch.name}") do
|
||||||
|
# Rugged seems to throw a `ReferenceError` when given branch_names rather
|
||||||
|
# than SHA-1 hashes
|
||||||
|
branch_sha = branch.dereferenced_target.sha
|
||||||
|
|
||||||
|
number_commits_behind, number_commits_ahead =
|
||||||
|
raw_repository.diverging_commit_count(
|
||||||
|
@root_ref_hash,
|
||||||
|
branch_sha)
|
||||||
|
|
||||||
|
{ behind: number_commits_behind, ahead: number_commits_ahead }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def archive_metadata(ref, storage_path, format = "tar.gz", append_sha:, path: nil)
|
def archive_metadata(ref, storage_path, format = "tar.gz", append_sha:, path: nil)
|
||||||
raw_repository.archive_metadata(
|
raw_repository.archive_metadata(
|
||||||
ref,
|
ref,
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Omit max-count for diverging_commit_counts behind feature flag
|
||||||
|
merge_request: 28157
|
||||||
|
author:
|
||||||
|
type: other
|
|
@ -500,7 +500,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return total diverging commits count
|
# Return total diverging commits count
|
||||||
def diverging_commit_count(from, to, max_count:)
|
def diverging_commit_count(from, to, max_count: 0)
|
||||||
wrapped_gitaly_errors do
|
wrapped_gitaly_errors do
|
||||||
gitaly_commit_client.diverging_commit_count(from, to, max_count: max_count)
|
gitaly_commit_client.diverging_commit_count(from, to, max_count: max_count)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2286,12 +2286,45 @@ describe Repository do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#diverging_commit_counts' do
|
describe '#diverging_commit_counts' do
|
||||||
|
let(:diverged_branch) { repository.find_branch('fix') }
|
||||||
|
let(:root_ref_sha) { repository.raw_repository.commit(repository.root_ref).id }
|
||||||
|
let(:diverged_branch_sha) { diverged_branch.dereferenced_target.sha }
|
||||||
|
|
||||||
it 'returns the commit counts behind and ahead of default branch' do
|
it 'returns the commit counts behind and ahead of default branch' do
|
||||||
result = repository.diverging_commit_counts(
|
result = repository.diverging_commit_counts(diverged_branch)
|
||||||
repository.find_branch('fix'))
|
|
||||||
|
|
||||||
expect(result).to eq(behind: 29, ahead: 2)
|
expect(result).to eq(behind: 29, ahead: 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when gitaly_count_diverging_commits_no_max is enabled' do
|
||||||
|
before do
|
||||||
|
stub_feature_flags(gitaly_count_diverging_commits_no_max: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'calls diverging_commit_count without max count' do
|
||||||
|
expect(repository.raw_repository)
|
||||||
|
.to receive(:diverging_commit_count)
|
||||||
|
.with(root_ref_sha, diverged_branch_sha)
|
||||||
|
.and_return([29, 2])
|
||||||
|
|
||||||
|
repository.diverging_commit_counts(diverged_branch)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when gitaly_count_diverging_commits_no_max is disabled' do
|
||||||
|
before do
|
||||||
|
stub_feature_flags(gitaly_count_diverging_commits_no_max: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'calls diverging_commit_count with max count' do
|
||||||
|
expect(repository.raw_repository)
|
||||||
|
.to receive(:diverging_commit_count)
|
||||||
|
.with(root_ref_sha, diverged_branch_sha, max_count: Repository::MAX_DIVERGING_COUNT)
|
||||||
|
.and_return([29, 2])
|
||||||
|
|
||||||
|
repository.diverging_commit_counts(diverged_branch)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#refresh_method_caches' do
|
describe '#refresh_method_caches' do
|
||||||
|
|
Loading…
Reference in New Issue