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:
authorRémy Coutable <remy@rymai.me>2018-03-28 19:16:33 +0300
committerRémy Coutable <remy@rymai.me>2018-03-28 19:16:33 +0300
commit141748929dd006e4b506028e44e7dfdf3988c936 (patch)
tree63d642060fb4f65a99a0d1ebf497ee37cceceea5
parentbe944a649032ccfa07f4f98cb2d048e14725fed1 (diff)
parent05b4b2d9679ccd09cf9723207603d0d3f670df30 (diff)
Merge branch '44657-reuse-root_ref_hash-on-branches' into 'master'
Avoid Gitaly n+1 times per request for Project Branches performance Closes #44657 et #37429 See merge request gitlab-org/gitlab-ce!17998
-rw-r--r--app/controllers/projects/branches_controller.rb16
-rw-r--r--app/models/repository.rb4
-rw-r--r--changelogs/unreleased/44657-reuse-root_ref_hash-on-branches.yml5
3 files changed, 13 insertions, 12 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb
index 965cece600e..176679f0849 100644
--- a/app/controllers/projects/branches_controller.rb
+++ b/app/controllers/projects/branches_controller.rb
@@ -21,17 +21,13 @@ class Projects::BranchesController < Projects::ApplicationController
fetch_branches_by_mode
@refs_pipelines = @project.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/37429
- 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[:behind], diverging_commit_counts[:ahead]].max
- end
-
- render
+ @merged_branch_names = repository.merged_branch_names(@branches.map(&:name))
+ @max_commits = @branches.reduce(0) do |memo, branch|
+ diverging_commit_counts = repository.diverging_commit_counts(branch)
+ [memo, diverging_commit_counts[:behind], diverging_commit_counts[:ahead]].max
end
+
+ render
end
format.json do
branches = BranchesFinder.new(@repository, params).execute
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 2ba1c6cb8c9..fd1afafe4df 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -249,13 +249,13 @@ class Repository
end
def diverging_commit_counts(branch)
- root_ref_hash = raw_repository.commit(root_ref).id
+ @root_ref_hash ||= raw_repository.commit(root_ref).id
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
# Rugged seems to throw a `ReferenceError` when given branch_names rather
# than SHA-1 hashes
number_commits_behind, number_commits_ahead =
raw_repository.count_commits_between(
- root_ref_hash,
+ @root_ref_hash,
branch.dereferenced_target.sha,
left_right: true,
max_count: MAX_DIVERGING_COUNT)
diff --git a/changelogs/unreleased/44657-reuse-root_ref_hash-on-branches.yml b/changelogs/unreleased/44657-reuse-root_ref_hash-on-branches.yml
new file mode 100644
index 00000000000..4f21aadd86b
--- /dev/null
+++ b/changelogs/unreleased/44657-reuse-root_ref_hash-on-branches.yml
@@ -0,0 +1,5 @@
+---
+title: Reuse root_ref_hash for performance on Branches
+merge_request: 17998
+author: Takuya Noguchi
+type: performance