Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
05b4b2d9
Commit
05b4b2d9
authored
Mar 27, 2018
by
Takuya Noguchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse root_ref_hash for performance on Branches
parent
a1cde68d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
12 deletions
+13
-12
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+6
-10
app/models/repository.rb
app/models/repository.rb
+2
-2
changelogs/unreleased/44657-reuse-root_ref_hash-on-branches.yml
...logs/unreleased/44657-reuse-root_ref_hash-on-branches.yml
+5
-0
No files found.
app/controllers/projects/branches_controller.rb
View file @
05b4b2d9
...
@@ -21,10 +21,7 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -21,10 +21,7 @@ class Projects::BranchesController < Projects::ApplicationController
fetch_branches_by_mode
fetch_branches_by_mode
@refs_pipelines
=
@project
.
pipelines
.
latest_successful_for_refs
(
@branches
.
map
(
&
:name
))
@refs_pipelines
=
@project
.
pipelines
.
latest_successful_for_refs
(
@branches
.
map
(
&
:name
))
@merged_branch_names
=
@merged_branch_names
=
repository
.
merged_branch_names
(
@branches
.
map
(
&
:name
))
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
|
@max_commits
=
@branches
.
reduce
(
0
)
do
|
memo
,
branch
|
diverging_commit_counts
=
repository
.
diverging_commit_counts
(
branch
)
diverging_commit_counts
=
repository
.
diverging_commit_counts
(
branch
)
[
memo
,
diverging_commit_counts
[
:behind
],
diverging_commit_counts
[
:ahead
]].
max
[
memo
,
diverging_commit_counts
[
:behind
],
diverging_commit_counts
[
:ahead
]].
max
...
@@ -32,7 +29,6 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -32,7 +29,6 @@ class Projects::BranchesController < Projects::ApplicationController
render
render
end
end
end
format
.
json
do
format
.
json
do
branches
=
BranchesFinder
.
new
(
@repository
,
params
).
execute
branches
=
BranchesFinder
.
new
(
@repository
,
params
).
execute
branches
=
Kaminari
.
paginate_array
(
branches
).
page
(
params
[
:page
])
branches
=
Kaminari
.
paginate_array
(
branches
).
page
(
params
[
:page
])
...
...
app/models/repository.rb
View file @
05b4b2d9
...
@@ -253,13 +253,13 @@ class Repository
...
@@ -253,13 +253,13 @@ class Repository
end
end
def
diverging_commit_counts
(
branch
)
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
cache
.
fetch
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
do
# Rugged seems to throw a `ReferenceError` when given branch_names rather
# Rugged seems to throw a `ReferenceError` when given branch_names rather
# than SHA-1 hashes
# than SHA-1 hashes
number_commits_behind
,
number_commits_ahead
=
number_commits_behind
,
number_commits_ahead
=
raw_repository
.
count_commits_between
(
raw_repository
.
count_commits_between
(
root_ref_hash
,
@
root_ref_hash
,
branch
.
dereferenced_target
.
sha
,
branch
.
dereferenced_target
.
sha
,
left_right:
true
,
left_right:
true
,
max_count:
MAX_DIVERGING_COUNT
)
max_count:
MAX_DIVERGING_COUNT
)
...
...
changelogs/unreleased/44657-reuse-root_ref_hash-on-branches.yml
0 → 100644
View file @
05b4b2d9
---
title
:
Reuse root_ref_hash for performance on Branches
merge_request
:
17998
author
:
Takuya Noguchi
type
:
performance
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment