Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/branches.rb')
-rw-r--r--lib/api/branches.rb48
1 files changed, 32 insertions, 16 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index 6842e93a4de..1ee120f982a 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -38,22 +38,38 @@ module API
optional :page_token, type: String, desc: 'Name of branch to start the paginaition from'
end
get ':id/repository/branches' do
- user_project.preload_protected_branches
-
- repository = user_project.repository
-
- branches_finder = BranchesFinder.new(repository, declared_params(include_missing: false))
- branches = Gitlab::Pagination::GitalyKeysetPager.new(self, user_project).paginate(branches_finder)
-
- merged_branch_names = repository.merged_branch_names(branches.map(&:name))
-
- present(
- branches,
- with: Entities::Branch,
- current_user: current_user,
- project: user_project,
- merged_branch_names: merged_branch_names
- )
+ ff_enabled = Feature.enabled?(:api_caching_rate_limit_branches, user_project, default_enabled: :yaml)
+
+ cache_action_if(ff_enabled, [user_project, :branches, current_user, declared_params], expires_in: 30.seconds) do
+ user_project.preload_protected_branches
+
+ repository = user_project.repository
+
+ branches_finder = BranchesFinder.new(repository, declared_params(include_missing: false))
+ branches = Gitlab::Pagination::GitalyKeysetPager.new(self, user_project).paginate(branches_finder)
+
+ merged_branch_names = repository.merged_branch_names(branches.map(&:name))
+
+ if Feature.enabled?(:api_caching_branches, user_project, type: :development, default_enabled: :yaml)
+ present_cached(
+ branches,
+ with: Entities::Branch,
+ current_user: current_user,
+ project: user_project,
+ merged_branch_names: merged_branch_names,
+ expires_in: 10.minutes,
+ cache_context: -> (branch) { [current_user&.cache_key, merged_branch_names.include?(branch.name)] }
+ )
+ else
+ present(
+ branches,
+ with: Entities::Branch,
+ current_user: current_user,
+ project: user_project,
+ merged_branch_names: merged_branch_names
+ )
+ end
+ end
end
resource ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do