Skip to content
Snippets Groups Projects
Commit 8f5bc219 authored by Robert May's avatar Robert May
Browse files

Cache rendered compare entity

parent 32f89255
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -25,6 +25,10 @@ def initialize(compare, project, base_sha: nil, straight: false)
@straight = straight
end
 
def cache_key
[@project, :compare, start_commit_sha, base_commit_sha, head_commit_sha, @straight]
end
def commits
@commits ||= Commit.decorate(@compare.commits, project)
end
Loading
Loading
---
name: api_caching_repository_compare
introduced_by_url:
rollout_issue_url:
milestone: '14.0'
type: development
group: group::source code
default_enabled: false
Loading
Loading
@@ -138,7 +138,11 @@ def assign_blob_vars!
compare = CompareService.new(user_project, params[:to]).execute(target_project, params[:from], straight: params[:straight])
 
if compare
present compare, with: Entities::Compare
if Feature.enabled?(:api_caching_repository_compare, user_project, default_enabled: :yaml)
present_cached compare, with: Entities::Compare, expires_in: 1.day, cache_context: nil
else
present compare, with: Entities::Compare
end
else
not_found!("Ref")
end
Loading
Loading
Loading
Loading
@@ -13,7 +13,16 @@
 
let(:raw_compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, start_commit.id, head_commit.id) }
 
subject { described_class.new(raw_compare, project) }
subject(:compare) { described_class.new(raw_compare, project) }
describe '#cache_key' do
subject { compare.cache_key }
it { is_expected.to include(project) }
it { is_expected.to include(start_commit.id) }
it { is_expected.to include(head_commit.id) }
it { is_expected.to include(compare.base_commit_sha) }
end
 
describe '#start_commit' do
it 'returns raw compare base commit' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment