Commit b7019995 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'remove_feature_flags_for_diff_controller_performance' into 'master'

Remove the feature flags around improving the performance for diff_batches and metadata endpoints

See merge request gitlab-org/gitlab!36551
parents 44035b3c 0158de91
......@@ -1117,15 +1117,9 @@ class MergeRequest < ApplicationRecord
end
def source_branch_exists?
if Feature.enabled?(:memoize_source_branch_merge_request, project)
strong_memoize(:source_branch_exists) do
next false unless self.source_project
self.source_project.repository.branch_exists?(self.source_branch)
end
else
return false unless self.source_project
self.source_project.repository.branch_exists?(self.source_branch)
end
end
......
......@@ -29,13 +29,13 @@ module Gitlab
override :write_cache
def write_cache
highlight_cache.write_if_empty
diff_stats_cache&.write_if_empty(diff_stats_collection)
diff_stats_cache.write_if_empty(diff_stats_collection)
end
override :clear_cache
def clear_cache
highlight_cache.clear
diff_stats_cache&.clear
diff_stats_cache.clear
end
def real_size
......@@ -52,18 +52,16 @@ module Gitlab
def diff_stats_cache
strong_memoize(:diff_stats_cache) do
if Feature.enabled?(:cache_diff_stats_merge_request, project)
Gitlab::Diff::StatsCache.new(cachable_key: @merge_request_diff.cache_key)
end
end
end
override :diff_stats_collection
def diff_stats_collection
strong_memoize(:diff_stats) do
next unless fetch_diff_stats?
diff_stats_cache&.read || super
diff_stats_cache.read || super
end
end
end
......
......@@ -1248,11 +1248,6 @@ RSpec.describe MergeRequest do
let(:merge_request) { subject }
let(:repository) { merge_request.source_project.repository }
context 'when memoize_source_branch_merge_request feature is enabled' do
before do
stub_feature_flags(memoize_source_branch_merge_request: true)
end
context 'when the source project is set' do
it 'memoizes the value and returns the result' do
expect(repository).to receive(:branch_exists?).once.with(merge_request.source_branch).and_return(true)
......@@ -1272,31 +1267,6 @@ RSpec.describe MergeRequest do
end
end
context 'when memoize_source_branch_merge_request feature is disabled' do
before do
stub_feature_flags(memoize_source_branch_merge_request: false)
end
context 'when the source project is set' do
it 'does not memoize the value and returns the result' do
expect(repository).to receive(:branch_exists?).twice.with(merge_request.source_branch).and_return(true)
2.times { expect(merge_request.source_branch_exists?).to eq(true) }
end
end
context 'when the source project is not set' do
before do
merge_request.source_project = nil
end
it 'returns false' do
expect(merge_request.source_branch_exists?).to eq(false)
end
end
end
end
describe '#default_merge_commit_message' do
it 'includes merge information as the title' do
request = build(:merge_request, source_branch: 'source', target_branch: 'target')
......
......@@ -67,18 +67,16 @@ RSpec.shared_examples 'cacheable diff collection' do
end
describe '#write_cache' do
before do
expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache }
end
it 'calls Gitlab::Diff::HighlightCache#write_if_empty' do
expect(highlight_cache).to receive(:write_if_empty).once
subject.write_cache
end
context 'when the feature flag is enabled' do
before do
stub_feature_flags(cache_diff_stats_merge_request: true)
expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache }
end
it 'calls Gitlab::Diff::StatsCache#write_if_empty with diff stats' do
diff_stats = Gitlab::Git::DiffStatsCollection.new([])
......@@ -91,32 +89,17 @@ RSpec.shared_examples 'cacheable diff collection' do
end
end
context 'when the feature flag is disabled' do
describe '#clear_cache' do
before do
stub_feature_flags(cache_diff_stats_merge_request: false)
end
it 'does not call Gitlab::Diff::StatsCache#write_if_empty' do
expect(stats_cache).not_to receive(:write_if_empty)
subject.write_cache
end
end
expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache }
end
describe '#clear_cache' do
it 'calls Gitlab::Diff::HighlightCache#clear' do
expect(highlight_cache).to receive(:clear).once
subject.clear_cache
end
context 'when the feature flag is enabled' do
before do
stub_feature_flags(cache_diff_stats_merge_request: true)
expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache }
end
it 'calls Gitlab::Diff::StatsCache#clear' do
expect(stats_cache).to receive(:clear).once
......@@ -124,20 +107,11 @@ RSpec.shared_examples 'cacheable diff collection' do
end
end
context 'when the feature flag is disabled' do
describe '#diff_files' do
before do
stub_feature_flags(cache_diff_stats_merge_request: false)
end
it 'does not calls Gitlab::Diff::StatsCache#clear' do
expect(stats_cache).not_to receive(:clear)
subject.clear_cache
end
end
expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache }
end
describe '#diff_files' do
it 'calls Gitlab::Diff::HighlightCache#decorate' do
expect(highlight_cache).to receive(:decorate)
.with(instance_of(Gitlab::Diff::File))
......@@ -146,12 +120,6 @@ RSpec.shared_examples 'cacheable diff collection' do
subject.diff_files
end
context 'when the feature swtich is enabled' do
before do
stub_feature_flags(cache_diff_stats_merge_request: true)
expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache }
end
context 'when there are stats cached' do
before do
allow(stats_cache).to receive(:read).and_return(Gitlab::Git::DiffStatsCollection.new([]))
......@@ -174,19 +142,4 @@ RSpec.shared_examples 'cacheable diff collection' do
end
end
end
context 'when the feature switch is disabled' do
before do
stub_feature_flags(cache_diff_stats_merge_request: false)
end
it 'makes a diff stats rpc call' do
expect(diffable.project.repository)
.to receive(:diff_stats)
.with(diffable.diff_refs.base_sha, diffable.diff_refs.head_sha)
subject.diff_files
end
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