diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2019-06-18 17:20:11 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2019-06-28 16:22:35 +0300 |
commit | ca5cd7b7fb5108d30d0f6b74e31da736024592dd (patch) | |
tree | aec9468afa579b128b7e09f6e78e7357d6413b85 /app/controllers/projects/branches_controller.rb | |
parent | 546355f734f74c040d0ef0917ade50751fd90731 (diff) | |
download | gitlab-ce-ca5cd7b7fb5108d30d0f6b74e31da736024592dd.tar.gz |
Add endpoint for fetching diverging commit countsid-stale-branches
Extract diverging_commit_counts into a service class
Diffstat (limited to 'app/controllers/projects/branches_controller.rb')
-rw-r--r-- | app/controllers/projects/branches_controller.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index fc708400657..da5efe4f21c 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -25,15 +25,6 @@ class Projects::BranchesController < Projects::ApplicationController @refs_pipelines = @project.ci_pipelines.latest_successful_for_refs(@branches.map(&:name)) @merged_branch_names = repository.merged_branch_names(@branches.map(&:name)) - # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/48097 - Gitlab::GitalyClient.allow_n_plus_1_calls do - @max_commits = @branches.reduce(0) do |memo, branch| - diverging_commit_counts = repository.diverging_commit_counts(branch) - [memo, diverging_commit_counts.values_at(:behind, :ahead, :distance)] - .flatten.compact.max - end - end - # https://gitlab.com/gitlab-org/gitlab-ce/issues/48097 Gitlab::GitalyClient.allow_n_plus_1_calls do render @@ -51,6 +42,19 @@ class Projects::BranchesController < Projects::ApplicationController @branches = @repository.recent_branches end + def diverging_commit_counts + respond_to do |format| + format.json do + service = Branches::DivergingCommitCountsService.new(repository) + branches = BranchesFinder.new(repository, params.permit(names: [])).execute + + Gitlab::GitalyClient.allow_n_plus_1_calls do + render json: branches.to_h { |branch| [branch.name, service.call(branch)] } + end + end + end + end + # rubocop: disable CodeReuse/ActiveRecord def create branch_name = strip_tags(sanitize(params[:branch_name])) |