From c838243a90359d9570deb77f5889f809a5fd1997 Mon Sep 17 00:00:00 2001 From: Justin Tobler Date: Thu, 8 Feb 2024 16:28:10 -0600 Subject: [PATCH] repository: Disable file history rename detection When viewing the commit history of a file, the `FindCommits` Gitaly RPC is invoked with the `follow` option enabled. This instructs the underlying `git-log(1)` operation to follow file renames when fetching commit history. This rename detection can be rather expensive for repositories with deep commit history and result in long file commit history load times. Introduce the `remove_file_commit_history_following` feature flag which, when enabled, prevents rename detection from being performed when finding commits for a single file. --- app/models/repository.rb | 2 +- .../remove_file_commit_history_following.yml | 9 +++++++++ spec/models/repository_spec.rb | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 config/feature_flags/ops/remove_file_commit_history_following.yml diff --git a/app/models/repository.rb b/app/models/repository.rb index 6045b899743b5d..ae39056b774da4 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -153,7 +153,7 @@ def commits(ref = nil, opts = {}) ref: ref, path: opts[:path], author: opts[:author], - follow: Array(opts[:path]).length == 1, + follow: Array(opts[:path]).length == 1 && Feature.disabled?(:remove_file_commit_history_following, type: :ops), limit: opts[:limit], offset: opts[:offset], skip_merges: !!opts[:skip_merges], diff --git a/config/feature_flags/ops/remove_file_commit_history_following.yml b/config/feature_flags/ops/remove_file_commit_history_following.yml new file mode 100644 index 00000000000000..872bcf1ab645ee --- /dev/null +++ b/config/feature_flags/ops/remove_file_commit_history_following.yml @@ -0,0 +1,9 @@ +--- +name: remove_file_commit_history_following +feature_issue_url: https://gitlab.com/gitlab-org/gitaly/-/issues/5821 +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/144263 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/441312 +milestone: '16.10' +group: group::gitaly +type: ops +default_enabled: false diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index b6cb2464605d8c..25afbd625b306b 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -398,8 +398,21 @@ def expect_to_raise_storage_error end context 'with path' do - it 'sets follow when it is a single path' do - expect(Gitlab::Git::Commit).to receive(:where).with(a_hash_including(follow: true)).and_call_original.twice + context 'when remove_file_commit_history_following feature flag is disabled' do + before do + stub_feature_flags(remove_file_commit_history_following: false) + end + + it 'sets follow when it is a single path' do + expect(Gitlab::Git::Commit).to receive(:where).with(a_hash_including(follow: true)).and_call_original.twice + + repository.commits('master', limit: 1, path: 'README.md') + repository.commits('master', limit: 1, path: ['README.md']) + end + end + + it 'does not set follow when it is a single path' do + expect(Gitlab::Git::Commit).to receive(:where).with(a_hash_including(follow: false)).and_call_original.twice repository.commits('master', limit: 1, path: 'README.md') repository.commits('master', limit: 1, path: ['README.md']) -- GitLab