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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
41bb23ae
Commit
41bb23ae
authored
Feb 13, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore memoization to base query and add a batch base query method
parent
4fcbcce3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
11 deletions
+16
-11
app/models/cycle_analytics.rb
app/models/cycle_analytics.rb
+7
-2
app/serializers/analytics_stage_entity.rb
app/serializers/analytics_stage_entity.rb
+1
-1
lib/gitlab/cycle_analytics/base_query.rb
lib/gitlab/cycle_analytics/base_query.rb
+5
-5
lib/gitlab/cycle_analytics/base_stage.rb
lib/gitlab/cycle_analytics/base_stage.rb
+1
-1
lib/gitlab/cycle_analytics/production_helper.rb
lib/gitlab/cycle_analytics/production_helper.rb
+1
-1
lib/gitlab/cycle_analytics/test_stage.rb
lib/gitlab/cycle_analytics/test_stage.rb
+1
-1
No files found.
app/models/cycle_analytics.rb
View file @
41bb23ae
...
@@ -7,8 +7,13 @@ class CycleAnalytics
...
@@ -7,8 +7,13 @@ class CycleAnalytics
end
end
def
all_medians_per_stage
def
all_medians_per_stage
STAGES
.
each_with_object
({})
do
|
stage_name
,
hsh
|
medians_per_stage
=
{}
hsh
[
stage_name
]
=
self
[
stage_name
].
median
# We only need this data for Postgres instances
return
medians_per_stage
if
Gitlab
::
Database
.
mysql?
STAGES
.
each
do
|
stage_name
|
medians_per_stage
[
stage_name
]
=
self
[
stage_name
].
median
end
end
end
end
...
...
app/serializers/analytics_stage_entity.rb
View file @
41bb23ae
...
@@ -7,6 +7,6 @@ class AnalyticsStageEntity < Grape::Entity
...
@@ -7,6 +7,6 @@ class AnalyticsStageEntity < Grape::Entity
expose
:description
expose
:description
expose
:median
,
as: :value
do
|
stage
|
expose
:median
,
as: :value
do
|
stage
|
stage
.
median
&&
!
stage
.
median
.
blank?
?
distance_of_time_in_words
(
stage
.
median
)
:
nil
distance_of_time_in_words
(
stage
.
median
)
if
stage
.
median
&&
!
(
stage
.
median
.
blank?
||
stage
.
median
.
zero?
)
end
end
end
end
lib/gitlab/cycle_analytics/base_query.rb
View file @
41bb23ae
...
@@ -7,14 +7,15 @@ module Gitlab
...
@@ -7,14 +7,15 @@ module Gitlab
private
private
def
base_query
(
project_ids
=
nil
)
def
base_query
stage_query
(
project_ids
)
@base_query
||=
stage_query
([
@project
.
id
]
)
end
end
def
stage_query
(
project_ids
=
nil
)
def
stage_query
(
project_ids
)
query
=
mr_closing_issues_table
.
join
(
issue_table
).
on
(
issue_table
[
:id
].
eq
(
mr_closing_issues_table
[
:issue_id
]))
query
=
mr_closing_issues_table
.
join
(
issue_table
).
on
(
issue_table
[
:id
].
eq
(
mr_closing_issues_table
[
:issue_id
]))
.
join
(
issue_metrics_table
).
on
(
issue_table
[
:id
].
eq
(
issue_metrics_table
[
:issue_id
]))
.
join
(
issue_metrics_table
).
on
(
issue_table
[
:id
].
eq
(
issue_metrics_table
[
:issue_id
]))
.
where
(
issue_table
[
:project_id
].
in
(
project_ids
||
@project
.
id
))
# rubocop:disable Gitlab/ModuleWithInstanceVariables
.
project
(
issue_table
[
:project_id
].
as
(
"project_id"
))
.
where
(
issue_table
[
:project_id
].
in
(
project_ids
))
# rubocop:disable Gitlab/ModuleWithInstanceVariables
.
where
(
issue_table
[
:created_at
].
gteq
(
@options
[
:from
]))
# rubocop:disable Gitlab/ModuleWithInstanceVariables
.
where
(
issue_table
[
:created_at
].
gteq
(
@options
[
:from
]))
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# Load merge_requests
# Load merge_requests
...
@@ -22,7 +23,6 @@ module Gitlab
...
@@ -22,7 +23,6 @@ module Gitlab
.
on
(
mr_table
[
:id
].
eq
(
mr_closing_issues_table
[
:merge_request_id
]))
.
on
(
mr_table
[
:id
].
eq
(
mr_closing_issues_table
[
:merge_request_id
]))
.
join
(
mr_metrics_table
)
.
join
(
mr_metrics_table
)
.
on
(
mr_table
[
:id
].
eq
(
mr_metrics_table
[
:merge_request_id
]))
.
on
(
mr_table
[
:id
].
eq
(
mr_metrics_table
[
:merge_request_id
]))
.
project
(
issue_table
[
:project_id
].
as
(
"project_id"
))
query
query
end
end
...
...
lib/gitlab/cycle_analytics/base_stage.rb
View file @
41bb23ae
...
@@ -29,7 +29,7 @@ module Gitlab
...
@@ -29,7 +29,7 @@ module Gitlab
# We compute the (end_time - start_time) interval, and give it an alias based on the current
# We compute the (end_time - start_time) interval, and give it an alias based on the current
# cycle analytics stage.
# cycle analytics stage.
interval_query
=
Arel
::
Nodes
::
As
.
new
(
cte_table
,
interval_query
=
Arel
::
Nodes
::
As
.
new
(
cte_table
,
subtract_datetimes
(
bas
e_query
(
project_ids
),
start_time_attrs
,
end_time_attrs
,
name
.
to_s
))
subtract_datetimes
(
stag
e_query
(
project_ids
),
start_time_attrs
,
end_time_attrs
,
name
.
to_s
))
median_datetimes
(
cte_table
,
interval_query
,
name
,
:project_id
)
&
.
each
do
|
project_id
,
median
|
median_datetimes
(
cte_table
,
interval_query
,
name
,
:project_id
)
&
.
each
do
|
project_id
,
median
|
loader
.
call
(
project_id
,
median
)
loader
.
call
(
project_id
,
median
)
...
...
lib/gitlab/cycle_analytics/production_helper.rb
View file @
41bb23ae
module
Gitlab
module
Gitlab
module
CycleAnalytics
module
CycleAnalytics
module
ProductionHelper
module
ProductionHelper
def
stage_query
(
project_ids
=
nil
)
def
stage_query
(
project_ids
)
super
(
project_ids
)
super
(
project_ids
)
.
where
(
mr_metrics_table
[
:first_deployed_to_production_at
]
.
where
(
mr_metrics_table
[
:first_deployed_to_production_at
]
.
gteq
(
@options
[
:from
]))
# rubocop:disable Gitlab/ModuleWithInstanceVariables
.
gteq
(
@options
[
:from
]))
# rubocop:disable Gitlab/ModuleWithInstanceVariables
...
...
lib/gitlab/cycle_analytics/test_stage.rb
View file @
41bb23ae
...
@@ -25,7 +25,7 @@ module Gitlab
...
@@ -25,7 +25,7 @@ module Gitlab
_
(
"Total test time for all commits/merges"
)
_
(
"Total test time for all commits/merges"
)
end
end
def
stage_query
(
project_ids
=
nil
)
def
stage_query
(
project_ids
)
if
@options
[
:branch
]
if
@options
[
:branch
]
super
(
project_ids
).
where
(
build_table
[
:ref
].
eq
(
@options
[
:branch
]))
super
(
project_ids
).
where
(
build_table
[
:ref
].
eq
(
@options
[
:branch
]))
else
else
...
...
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