BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
55f4869a
Commit
55f4869a
authored
Jun 26, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'zj-faster-charts-page' into 'master'
Improve performance for pipeline charts Closes #32407 See merge request !12378
parents
5c8e8662
7ccc6322
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
35 additions
and
33 deletions
+35
-33
pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+6
-1
graph_helper.rb
app/helpers/graph_helper.rb
+3
-6
charts.html.haml
app/views/projects/pipelines/charts.html.haml
+2
-2
_overall.haml
app/views/projects/pipelines/charts/_overall.haml
+4
-8
_pipeline_times.haml
app/views/projects/pipelines/charts/_pipeline_times.haml
+2
-2
_pipelines.haml
app/views/projects/pipelines/charts/_pipelines.haml
+0
-0
zj-faster-charts-page.yml
changelogs/unreleased/zj-faster-charts-page.yml
+4
-0
charts.rb
lib/ci/charts.rb
+9
-9
charts_spec.rb
spec/lib/ci/charts_spec.rb
+5
-5
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
55f4869a
...
...
@@ -135,7 +135,12 @@ class Projects::PipelinesController < Projects::ApplicationController
@charts
[
:week
]
=
Ci
::
Charts
::
WeekChart
.
new
(
project
)
@charts
[
:month
]
=
Ci
::
Charts
::
MonthChart
.
new
(
project
)
@charts
[
:year
]
=
Ci
::
Charts
::
YearChart
.
new
(
project
)
@charts
[
:build_times
]
=
Ci
::
Charts
::
BuildTime
.
new
(
project
)
@charts
[
:pipeline_times
]
=
Ci
::
Charts
::
PipelineTime
.
new
(
project
)
@counts
=
{}
@counts
[
:total
]
=
@project
.
pipelines
.
count
(
:all
)
@counts
[
:success
]
=
@project
.
pipelines
.
success
.
count
(
:all
)
@counts
[
:failed
]
=
@project
.
pipelines
.
failed
.
count
(
:all
)
end
private
...
...
app/helpers/graph_helper.rb
View file @
55f4869a
...
...
@@ -17,13 +17,10 @@ module GraphHelper
ids
.
zip
(
parent_spaces
)
end
def
success_ratio
(
success_builds
,
failed_builds
)
failed_builds
=
failed_builds
.
count
(
:all
)
success_builds
=
success_builds
.
count
(
:all
)
def
success_ratio
(
counts
)
return
100
if
counts
[
:failed
].
zero?
return
100
if
failed_builds
.
zero?
ratio
=
(
success_builds
.
to_f
/
(
success_builds
+
failed_builds
))
*
100
ratio
=
(
counts
[
:success
].
to_f
/
(
counts
[
:success
]
+
counts
[
:failed
]))
*
100
ratio
.
to_i
end
end
app/views/projects/pipelines/charts.html.haml
View file @
55f4869a
...
...
@@ -15,7 +15,7 @@
.col-md-6
=
render
'projects/pipelines/charts/overall'
.col-md-6
=
render
'projects/pipelines/charts/
build
_times'
=
render
'projects/pipelines/charts/
pipeline
_times'
%hr
=
render
'projects/pipelines/charts/
build
s'
=
render
'projects/pipelines/charts/
pipeline
s'
app/views/projects/pipelines/charts/_overall.haml
View file @
55f4869a
...
...
@@ -2,18 +2,14 @@
%ul
%li
Total:
%strong
=
pluralize
@
project
.
builds
.
count
(
:all
),
'job
'
%strong
=
pluralize
@
counts
[
:total
],
'pipeline
'
%li
Successful:
%strong
=
pluralize
@
project
.
builds
.
success
.
count
(
:all
),
'job
'
%strong
=
pluralize
@
counts
[
:success
],
'pipeline
'
%li
Failed:
%strong
=
pluralize
@
project
.
builds
.
failed
.
count
(
:all
),
'job
'
%strong
=
pluralize
@
counts
[
:failed
],
'pipeline
'
%li
Success ratio:
%strong
#{
success_ratio
(
@project
.
builds
.
success
,
@project
.
builds
.
failed
)
}
%
%li
Commits covered:
%strong
=
@project
.
pipelines
.
count
(
:all
)
#{
success_ratio
(
@counts
)
}
%
app/views/projects/pipelines/charts/_
build
_times.haml
→
app/views/projects/pipelines/charts/_
pipeline
_times.haml
View file @
55f4869a
...
...
@@ -6,7 +6,7 @@
:javascript
var
data
=
{
labels
:
#{
@charts
[
:
build
_times
].
labels
.
to_json
}
,
labels
:
#{
@charts
[
:
pipeline
_times
].
labels
.
to_json
}
,
datasets
:
[
{
fillColor
:
"rgba(220,220,220,0.5)"
,
...
...
@@ -14,7 +14,7 @@
barStrokeWidth
:
1
,
barValueSpacing
:
1
,
barDatasetSpacing
:
1
,
data
:
#{
@charts
[
:
build_times
].
build
_times
.
to_json
}
data
:
#{
@charts
[
:
pipeline_times
].
pipeline
_times
.
to_json
}
}
]
}
...
...
app/views/projects/pipelines/charts/_
build
s.haml
→
app/views/projects/pipelines/charts/_
pipeline
s.haml
View file @
55f4869a
File moved
changelogs/unreleased/zj-faster-charts-page.yml
0 → 100644
View file @
55f4869a
---
title
:
Improve performance of the pipeline charts page
merge_request
:
12378
author
:
lib/ci/charts.rb
View file @
55f4869a
...
...
@@ -3,7 +3,7 @@ module Ci
module
DailyInterval
def
grouped_count
(
query
)
query
.
group
(
"DATE(
#{
Ci
::
Build
.
table_name
}
.created_at)"
)
.
group
(
"DATE(
#{
Ci
::
Pipeline
.
table_name
}
.created_at)"
)
.
count
(
:created_at
)
.
transform_keys
{
|
date
|
date
.
strftime
(
@format
)
}
end
...
...
@@ -17,12 +17,12 @@ module Ci
def
grouped_count
(
query
)
if
Gitlab
::
Database
.
postgresql?
query
.
group
(
"to_char(
#{
Ci
::
Build
.
table_name
}
.created_at, '01 Month YYYY')"
)
.
group
(
"to_char(
#{
Ci
::
Pipeline
.
table_name
}
.created_at, '01 Month YYYY')"
)
.
count
(
:created_at
)
.
transform_keys
(
&
:squish
)
else
query
.
group
(
"DATE_FORMAT(
#{
Ci
::
Build
.
table_name
}
.created_at, '01 %M %Y')"
)
.
group
(
"DATE_FORMAT(
#{
Ci
::
Pipeline
.
table_name
}
.created_at, '01 %M %Y')"
)
.
count
(
:created_at
)
end
end
...
...
@@ -33,21 +33,21 @@ module Ci
end
class
Chart
attr_reader
:labels
,
:total
,
:success
,
:project
,
:
build
_times
attr_reader
:labels
,
:total
,
:success
,
:project
,
:
pipeline
_times
def
initialize
(
project
)
@labels
=
[]
@total
=
[]
@success
=
[]
@
build
_times
=
[]
@
pipeline
_times
=
[]
@project
=
project
collect
end
def
collect
query
=
project
.
build
s
.
where
(
"? >
#{
Ci
::
Build
.
table_name
}
.created_at AND
#{
Ci
::
Build
.
table_name
}
.created_at > ?"
,
@to
,
@from
)
query
=
project
.
pipeline
s
.
where
(
"? >
#{
Ci
::
Pipeline
.
table_name
}
.created_at AND
#{
Ci
::
Pipeline
.
table_name
}
.created_at > ?"
,
@to
,
@from
)
totals_count
=
grouped_count
(
query
)
success_count
=
grouped_count
(
query
.
success
)
...
...
@@ -101,14 +101,14 @@ module Ci
end
end
class
Build
Time
<
Chart
class
Pipeline
Time
<
Chart
def
collect
commits
=
project
.
pipelines
.
last
(
30
)
commits
.
each
do
|
commit
|
@labels
<<
commit
.
short_sha
duration
=
commit
.
duration
||
0
@
build
_times
<<
(
duration
/
60
)
@
pipeline
_times
<<
(
duration
/
60
)
end
end
end
...
...
spec/lib/ci/charts_spec.rb
View file @
55f4869a
require
'spec_helper'
describe
Ci
::
Charts
,
lib:
true
do
context
"
build
_times"
do
context
"
pipeline
_times"
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:chart
)
{
Ci
::
Charts
::
Build
Time
.
new
(
project
)
}
let
(
:chart
)
{
Ci
::
Charts
::
Pipeline
Time
.
new
(
project
)
}
subject
{
chart
.
build
_times
}
subject
{
chart
.
pipeline
_times
}
before
do
create
(
:ci_empty_pipeline
,
project:
project
,
duration:
120
)
end
it
'returns
build
times in minutes'
do
it
'returns
pipeline
times in minutes'
do
is_expected
.
to
contain_exactly
(
2
)
end
it
'handles nil
build
times'
do
it
'handles nil
pipeline
times'
do
create
(
:ci_empty_pipeline
,
project:
project
,
duration:
nil
)
is_expected
.
to
contain_exactly
(
2
,
0
)
...
...
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