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
Léo-Paul Géneau
gitlab-ce
Commits
233d285c
Commit
233d285c
authored
Apr 26, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3741 from hiroponz/improve-performance-of-network-graph
Improve performance of network graph
parents
75fbdc40
1ae9c697
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
96 additions
and
52 deletions
+96
-52
app/assets/javascripts/branch-graph.js.coffee
app/assets/javascripts/branch-graph.js.coffee
+56
-39
app/assets/stylesheets/sections/graph.scss
app/assets/stylesheets/sections/graph.scss
+2
-1
app/helpers/graph_helper.rb
app/helpers/graph_helper.rb
+1
-2
app/models/network/graph.rb
app/models/network/graph.rb
+11
-2
features/project/network.feature
features/project/network.feature
+6
-4
features/steps/project/project_network_graph.rb
features/steps/project/project_network_graph.rb
+9
-0
lib/extracts_path.rb
lib/extracts_path.rb
+1
-3
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+10
-1
No files found.
app/assets/javascripts/branch-graph.js.coffee
View file @
233d285c
...
...
@@ -9,6 +9,7 @@ class BranchGraph
@
offsetY
=
20
@
unitTime
=
30
@
unitSpace
=
10
@
prev_start
=
-
1
@
load
()
load
:
->
...
...
@@ -24,10 +25,18 @@ class BranchGraph
prepareData
:
(
@
days
,
@
commits
)
->
@
collectParents
()
@
graphHeight
=
$
(
@
element
).
height
()
@
graphWidth
=
$
(
@
element
).
width
()
ch
=
Math
.
max
(
@
graphHeight
,
@
offsetY
+
@
unitTime
*
@
mtime
+
150
)
cw
=
Math
.
max
(
@
graphWidth
,
@
offsetX
+
@
unitSpace
*
@
mspace
+
300
)
@
r
=
Raphael
(
@
element
.
get
(
0
),
cw
,
ch
)
@
top
=
@
r
.
set
()
@
barHeight
=
Math
.
max
(
@
graphHeight
,
@
unitTime
*
@
days
.
length
+
320
)
for
c
in
@
commits
c
.
isParent
=
true
if
c
.
id
of
@
parents
@
preparedCommits
[
c
.
id
]
=
c
@
markCommit
(
c
)
@
collectColors
()
...
...
@@ -49,18 +58,12 @@ class BranchGraph
k
++
buildGraph
:
->
graphHeight
=
$
(
@
element
).
height
()
graphWidth
=
$
(
@
element
).
width
()
ch
=
Math
.
max
(
graphHeight
,
@
offsetY
+
@
unitTime
*
@
mtime
+
150
)
cw
=
Math
.
max
(
graphWidth
,
@
offsetX
+
@
unitSpace
*
@
mspace
+
300
)
@
r
=
r
=
Raphael
(
@
element
.
get
(
0
),
cw
,
ch
)
top
=
r
.
set
()
r
=
@
r
cuday
=
0
cumonth
=
""
barHeight
=
Math
.
max
(
graphHeight
,
@
unitTime
*
@
days
.
length
+
320
)
r
.
rect
(
0
,
0
,
26
,
barHeight
).
attr
fill
:
"#222"
r
.
rect
(
26
,
0
,
20
,
barHeight
).
attr
fill
:
"#444"
r
.
rect
(
0
,
0
,
26
,
@
barHeight
).
attr
fill
:
"#222"
r
.
rect
(
26
,
0
,
20
,
@
barHeight
).
attr
fill
:
"#444"
for
day
,
mm
in
@
days
if
cuday
isnt
day
[
0
]
...
...
@@ -81,7 +84,26 @@ class BranchGraph
)
cumonth
=
day
[
1
]
for
commit
in
@
commits
@
renderPartialGraph
()
@
bindEvents
()
renderPartialGraph
:
->
start
=
Math
.
floor
((
@
element
.
scrollTop
()
-
@
offsetY
)
/
@
unitTime
)
-
10
start
=
0
if
start
<
0
end
=
start
+
40
end
=
@
commits
.
length
if
@
commits
.
length
<
end
if
@
prev_start
==
-
1
or
Math
.
abs
(
@
prev_start
-
start
)
>
10
i
=
start
@
prev_start
=
start
while
i
<
end
commit
=
@
commits
[
i
]
i
+=
1
if
commit
.
hasDrawn
isnt
true
x
=
@
offsetX
+
@
unitSpace
*
(
@
mspace
-
commit
.
space
)
y
=
@
offsetY
+
@
unitTime
*
commit
.
time
...
...
@@ -89,34 +111,23 @@ class BranchGraph
@
drawLines
(
x
,
y
,
commit
)
@
appendLabel
(
x
,
y
,
commit
.
refs
)
if
commit
.
refs
@
appendLabel
(
x
,
y
,
commit
)
@
appendAnchor
(
top
,
commit
,
x
,
y
)
@
appendAnchor
(
x
,
y
,
commit
)
@
markCommit
(
x
,
y
,
commit
,
graphHeight
)
commit
.
hasDrawn
=
true
top
.
toFront
()
@
bindEvents
()
@
top
.
toFront
()
bindEvents
:
->
drag
=
{}
element
=
@
element
dragger
=
(
event
)
->
element
.
scrollLeft
drag
.
sl
-
(
event
.
clientX
-
drag
.
x
)
element
.
scrollTop
drag
.
st
-
(
event
.
clientY
-
drag
.
y
)
element
.
on
mousedown
:
(
event
)
->
drag
=
x
:
event
.
clientX
y
:
event
.
clientY
st
:
element
.
scrollTop
()
sl
:
element
.
scrollLeft
()
$
(
window
).
on
"mousemove"
,
dragger
$
(
element
).
scroll
(
event
)
=>
@
renderPartialGraph
()
$
(
window
).
on
mouseup
:
->
$
(
window
).
off
"mousemove"
,
dragger
keydown
:
(
event
)
->
keydown
:
(
event
)
=>
# left
element
.
scrollLeft
element
.
scrollLeft
()
-
50
if
event
.
keyCode
is
37
# top
...
...
@@ -125,17 +136,20 @@ class BranchGraph
element
.
scrollLeft
element
.
scrollLeft
()
+
50
if
event
.
keyCode
is
39
# bottom
element
.
scrollTop
element
.
scrollTop
()
+
50
if
event
.
keyCode
is
40
@
renderPartialGraph
()
appendLabel
:
(
x
,
y
,
commit
)
->
return
unless
commit
.
refs
appendLabel
:
(
x
,
y
,
refs
)
->
r
=
@
r
shortrefs
=
refs
shortrefs
=
commit
.
refs
# Truncate if longer than 15 chars
shortrefs
=
shortrefs
.
substr
(
0
,
15
)
+
"…"
if
shortrefs
.
length
>
17
text
=
r
.
text
(
x
+
4
,
y
,
shortrefs
).
attr
(
"text-anchor"
:
"start"
font
:
"10px Monaco, monospace"
fill
:
"#FFF"
title
:
refs
title
:
commit
.
refs
)
textbox
=
text
.
getBBox
()
# Create rectangle based on the size of the textbox
...
...
@@ -156,8 +170,9 @@ class BranchGraph
# Set text to front
text
.
toFront
()
appendAnchor
:
(
top
,
commit
,
x
,
y
)
->
appendAnchor
:
(
x
,
y
,
commit
)
->
r
=
@
r
top
=
@
top
options
=
@
options
anchor
=
r
.
circle
(
x
,
y
,
10
).
attr
(
fill
:
"#000"
...
...
@@ -240,16 +255,18 @@ class BranchGraph
stroke
:
color
"stroke-width"
:
2
)
markCommit
:
(
x
,
y
,
commit
,
graphHeigh
t
)
->
markCommit
:
(
commi
t
)
->
if
commit
.
id
is
@
options
.
commit_id
r
=
@
r
x
=
@
offsetX
+
@
unitSpace
*
(
@
mspace
-
commit
.
space
)
y
=
@
offsetY
+
@
unitTime
*
commit
.
time
r
.
path
([
"M"
,
x
+
5
,
y
,
"L"
,
x
+
15
,
y
+
4
,
"L"
,
x
+
15
,
y
-
4
,
"Z"
]).
attr
(
fill
:
"#000"
"fill-opacity"
:
.
5
stroke
:
"none"
)
# Displayed in the center
@
element
.
scrollTop
(
y
-
graphHeight
/
2
)
@
element
.
scrollTop
(
y
-
@
graphHeight
/
2
)
Raphael
::
commitTooltip
=
(
x
,
y
,
commit
)
->
boxWidth
=
300
...
...
app/assets/stylesheets/sections/graph.scss
View file @
233d285c
...
...
@@ -13,7 +13,8 @@
background
:
#f1f1f1
;
cursor
:
move
;
height
:
500px
;
overflow
:
hidden
;
overflow-y
:
scroll
;
overflow-x
:
hidden
;
}
}
app/helpers/graph_helper.rb
View file @
233d285c
...
...
@@ -4,8 +4,7 @@ module GraphHelper
refs
+=
commit
.
refs
.
collect
{
|
r
|
r
.
name
}.
join
(
" "
)
if
commit
.
refs
# append note count
notes
=
@project
.
notes
.
for_commit_id
(
commit
.
id
)
refs
+=
"[
#{
notes
.
count
}
]"
if
notes
.
any?
refs
+=
"[
#{
@graph
.
notes
[
commit
.
id
]
}
]"
if
@graph
.
notes
[
commit
.
id
]
>
0
refs
end
...
...
app/models/network/graph.rb
View file @
233d285c
...
...
@@ -2,7 +2,7 @@ require "grit"
module
Network
class
Graph
attr_reader
:days
,
:commits
,
:map
attr_reader
:days
,
:commits
,
:map
,
:notes
def
self
.
max_count
@max_count
||=
650
...
...
@@ -16,10 +16,19 @@ module Network
@commits
=
collect_commits
@days
=
index_commits
@notes
=
collect_notes
end
protected
def
collect_notes
h
=
Hash
.
new
(
0
)
@project
.
notes
.
where
(
'noteable_type = ?'
,
"Commit"
).
group
(
'notes.commit_id'
).
select
(
'notes.commit_id, count(notes.id) as note_count'
).
each
do
|
item
|
h
[
item
[
"commit_id"
]]
=
item
[
"note_count"
]
end
h
end
# Get commits from repository
#
def
collect_commits
...
...
@@ -181,7 +190,7 @@ module Network
l
.
spaces
<<
space
# Also add space to parent
l
.
parents
(
@map
).
each
do
|
parent
|
if
parent
.
space
>
0
if
0
<
parent
.
space
&&
parent
.
space
<
space
parent
.
spaces
<<
space
end
end
...
...
features/project/network.feature
View file @
233d285c
...
...
@@ -11,14 +11,16 @@ Feature: Project Network Graph
And
page should have
"master"
on graph
@javascript
Scenario
:
I
should switch
ref to
"stable
"
Scenario
:
I
should switch
"branch"
and
"tag
"
When
I switch ref to
"stable"
Then
page should have network graph
And
page should select
"stable"
in select box
Then
page should select
"stable"
in select box
And
page should have
"stable"
on graph
When
I switch ref to
"v2.1.0"
Then
page should select
"v2.1.0"
in select box
And
page should have
"v2.1.0"
on graph
@javascript
Scenario
:
I
should looking for a commit by SHA
of
"v2.1.0"
Scenario
:
I
should looking for a commit by SHA
When
I looking for a commit by SHA of
"v2.1.0"
Then
page should have network graph
And
page should select
"master"
in select box
...
...
features/steps/project/project_network_graph.rb
View file @
233d285c
...
...
@@ -30,10 +30,19 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
sleep
2
end
When
'I switch ref to "v2.1.0"'
do
page
.
select
'v2.1.0'
,
:from
=>
'ref'
sleep
2
end
And
'page should select "stable" in select box'
do
page
.
should
have_selector
'#ref_chzn span'
,
:text
=>
"stable"
end
And
'page should select "v2.1.0" in select box'
do
page
.
should
have_selector
'#ref_chzn span'
,
:text
=>
"v2.1.0"
end
And
'page should have "stable" on graph'
do
within
'.graph'
do
page
.
should
have_content
'stable'
...
...
lib/extracts_path.rb
View file @
233d285c
...
...
@@ -98,9 +98,7 @@ module ExtractsPath
@ref
,
@path
=
extract_ref
(
@id
)
# It is used "@project.repository.commits(@ref, @path, 1, 0)",
# because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.
@commit
=
@project
.
repository
.
commits
(
@ref
,
@path
,
1
,
0
).
first
@commit
=
@project
.
repository
.
commit
(
@ref
)
@tree
=
Tree
.
new
(
@project
.
repository
,
@commit
.
id
,
@ref
,
@path
)
...
...
lib/gitlab/git/repository.rb
View file @
233d285c
...
...
@@ -49,7 +49,16 @@ module Gitlab
def
commit
(
commit_id
=
nil
)
commit
=
if
commit_id
# Find repo.refs first,
# because if commit_id is "tag name",
# repo.commit(commit_id) returns wrong commit sha
# that is git tag object sha.
ref
=
repo
.
refs
.
find
{
|
r
|
r
.
name
==
commit_id
}
if
ref
ref
.
commit
else
repo
.
commit
(
commit_id
)
end
else
repo
.
commits
(
root_ref
).
first
end
...
...
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