diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 03:06:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 03:06:42 +0300 |
commit | b38cf7ccdf8b7ca90bce587a1bf4765631733017 (patch) | |
tree | 37b157087207cae5ec7b9e028864e859705c07d6 /app/controllers/projects | |
parent | 08f4ce10c04d705148a7e14556443b9e3aee6821 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/projects')
-rw-r--r-- | app/controllers/projects/branches_controller.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index c125ed3605a..578a3d451a7 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -11,6 +11,7 @@ class Projects::BranchesController < Projects::ApplicationController # Support legacy URLs before_action :redirect_for_legacy_index_sort_or_search, only: [:index] + before_action :limit_diverging_commit_counts!, only: [:diverging_commit_counts] def index respond_to do |format| @@ -125,6 +126,24 @@ class Projects::BranchesController < Projects::ApplicationController private + # It can be expensive to calculate the diverging counts for each + # branch. Normally the frontend should be specifying a set of branch + # names, but prior to + # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/32496, the + # frontend could omit this set. To prevent excessive I/O, we require + # that a list of names be specified. + def limit_diverging_commit_counts! + return unless Feature.enabled?(:limit_diverging_commit_counts, default_enabled: true) + + limit = Kaminari.config.default_per_page + + # If we don't have many branches in the repository, then go ahead. + return if project.repository.branch_count <= limit + return if params[:names].present? && Array(params[:names]).length <= limit + + render json: { error: "Specify at least one and at most #{limit} branch names" }, status: :unprocessable_entity + end + def ref if params[:ref] ref_escaped = strip_tags(sanitize(params[:ref])) |