Commit 432870f6 authored by David Fernandez's avatar David Fernandez

Merge branch 'id-cache-cache-merge-request-versions-version-api' into 'master'

Cache merge request diff version API [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!57568
parents 6f6f43bc 94dd7bf0
---
title: Cache merge request diff version API
merge_request: 57568
author:
type: performance
---
name: cached_api_merge_request_version
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57568
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/326093
milestone: '13.11'
type: development
group: group::source code
default_enabled: true
......@@ -45,8 +45,12 @@ module API
merge_request = find_merge_request_with_access(params[:merge_request_iid])
if Feature.enabled?(:cached_api_merge_request_version, default_enabled: :yaml)
present_cached merge_request.merge_request_diffs.find(params[:version_id]), with: Entities::MergeRequestDiffFull, cache_context: nil
else
present merge_request.merge_request_diffs.find(params[:version_id]), with: Entities::MergeRequestDiffFull
end
end
end
end
end
......@@ -75,5 +75,25 @@ RSpec.describe API::MergeRequestDiffs, 'MergeRequestDiffs' do
let(:url) { "/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}" }
end
end
context 'caching merge request diffs', :use_clean_rails_redis_caching do
it 'is performed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}", user)
expect(Rails.cache.fetch(merge_request_diff.cache_key)).to be_present
end
context 'when cached_api_merge_request_version is disabled' do
before do
stub_feature_flags(cached_api_merge_request_version: false)
end
it 'is not performed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}", user)
expect(Rails.cache.fetch(merge_request_diff.cache_key)).to be_nil
end
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