Commit 6929ff40 authored by Robert May's avatar Robert May

Cache entities for MR API

Adds caching for the generated API entities on
/api/:version/projects/:id/merge_requests.

Changelog: performance
parent b04fba39
---
name: api_caching_merge_requests
introduced_by_url:
rollout_issue_url:
milestone: '13.12'
type: development
group: group::source code
default_enabled: false
......@@ -201,7 +201,24 @@ module API
options = serializer_options_for(merge_requests).merge(project: user_project)
options[:project] = user_project
present merge_requests, options
if Feature.enabled?(:api_caching_merge_requests, user_project, type: :development, default_enabled: :yaml)
# User-specific context in the simple MR entity is limited to
# email address exposure, which we need to check and combine
# into the cache context
options[:cache_context] = proc do |mr|
[
mr.author.managed_by?(current_user),
mr.assignee.managed_by?(current_user),
mr.assignees.map { |u| u.managed_by?(current_user) },
[mr.metrics&.merged_by, mr.metrics&.latest_closed_by].compact.map { |u| u.managed_by?(current_user) },
options.values_at(:render_html, :with_labels_details, :skip_merge_status_recheck)
]
end
present_cached merge_requests, options
else
present merge_requests, options
end
end
desc 'Create a merge request' do
......
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