Commit 440519b6 authored by Thong Kuah's avatar Thong Kuah

Wrap changed code in feature flag

parent b12be5c7
......@@ -50,6 +50,8 @@ module Gitlab
def load_status
return if loaded?
return unless Gitlab::Ci::Features.pipeline_status_omit_commit_sha_in_cache_key?(project) || commit
if has_cache?
load_from_cache
else
......@@ -115,7 +117,11 @@ module Gitlab
end
def cache_key
"#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:project:#{project.id}:pipeline_status"
if Gitlab::Ci::Features.pipeline_status_omit_commit_sha_in_cache_key?(project)
"#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:project:#{project.id}:pipeline_status"
else
"#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:project:#{project.id}:pipeline_status:#{commit&.sha}"
end
end
def commit
......
......@@ -34,6 +34,10 @@ module Gitlab
::Feature.enabled?(:ci_pipeline_latest, default_enabled: true)
end
def self.pipeline_status_omit_commit_sha_in_cache_key?(project)
Feature.enabled?(:ci_pipeline_status_omit_commit_sha_in_cache_key, project)
end
def self.release_generation_enabled?
::Feature.enabled?(:ci_release_generation)
end
......
......@@ -83,8 +83,24 @@ RSpec.describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cac
expect(pipeline_status).not_to be_has_cache
end
it 'makes a Gitaly call' do
expect { pipeline_status.load_status }.to change { Gitlab::GitalyClient.get_request_count }.by(1)
context 'ci_pipeline_status_omit_commit_sha_in_cache_key is enabled' do
before do
stub_feature_flags(ci_pipeline_status_omit_commit_sha_in_cache_key: project)
end
it 'makes a Gitaly call' do
expect { pipeline_status.load_status }.to change { Gitlab::GitalyClient.get_request_count }.by(1)
end
end
context 'ci_pipeline_status_omit_commit_sha_in_cache_key is disabled' do
before do
stub_feature_flags(ci_pipeline_status_omit_commit_sha_in_cache_key: false)
end
it 'makes a Gitaly calls' do
expect { pipeline_status.load_status }.to change { Gitlab::GitalyClient.get_request_count }.by(1)
end
end
end
......@@ -95,8 +111,24 @@ RSpec.describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cac
expect(pipeline_status).to be_has_cache
end
it 'makes no Gitaly calls' do
expect { pipeline_status.load_status }.to change { Gitlab::GitalyClient.get_request_count }.by(0)
context 'ci_pipeline_status_omit_commit_sha_in_cache_key is enabled' do
before do
stub_feature_flags(ci_pipeline_status_omit_commit_sha_in_cache_key: project)
end
it 'makes no Gitaly calls' do
expect { pipeline_status.load_status }.to change { Gitlab::GitalyClient.get_request_count }.by(0)
end
end
context 'ci_pipeline_status_omit_commit_sha_in_cache_key is disabled' do
before do
stub_feature_flags(ci_pipeline_status_omit_commit_sha_in_cache_key: false)
end
it 'makes a Gitaly calls' do
expect { pipeline_status.load_status }.to change { Gitlab::GitalyClient.get_request_count }.by(1)
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