Commit 1810dfb3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'reduce_pipeline_status_gitaly_call' into 'master'

Remove need to call gitaly in ProjectPipelineStatus

Closes gitlab-foss#52780

See merge request gitlab-org/gitlab!33712
parents bcd854f1 440519b6
---
title: Remove need to call commit (gitaly call) in ProjectPipelineStatus
merge_request: 33712
author:
type: performance
......@@ -49,7 +49,8 @@ module Gitlab
def load_status
return if loaded?
return unless commit
return unless Gitlab::Ci::Features.pipeline_status_omit_commit_sha_in_cache_key?(project) || commit
if has_cache?
load_from_cache
......@@ -66,6 +67,8 @@ module Gitlab
end
def load_from_project
return unless commit
self.sha, self.status, self.ref = commit.sha, commit.status, project.default_branch
end
......@@ -114,8 +117,12 @@ module Gitlab
end
def cache_key
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
strong_memoize(:commit) do
......
......@@ -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
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do
let!(:project) { create(:project, :repository) }
let_it_be(:project) { create(:project, :repository) }
let(:pipeline_status) { described_class.new(project) }
let(:cache_key) { pipeline_status.cache_key }
......@@ -77,6 +77,62 @@ RSpec.describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cac
end
describe '#load_status' do
describe 'gitaly call counts', :request_store do
context 'not cached' do
before do
expect(pipeline_status).not_to be_has_cache
end
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
context 'cached' do
before do
described_class.load_in_batch_for_projects([project])
expect(pipeline_status).to be_has_cache
end
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
it 'loads the status from the cache when there is one' do
expect(pipeline_status).to receive(:has_cache?).and_return(true)
expect(pipeline_status).to receive(:load_from_cache)
......
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