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
abca34d0
Commit
abca34d0
authored
Jul 04, 2019
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify base class for cycle analytics fetching
parent
68a5e205
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
17 deletions
+34
-17
lib/gitlab/cycle_analytics/base_event_fetcher.rb
lib/gitlab/cycle_analytics/base_event_fetcher.rb
+6
-2
lib/gitlab/cycle_analytics/base_query.rb
lib/gitlab/cycle_analytics/base_query.rb
+1
-1
lib/gitlab/cycle_analytics/base_stage.rb
lib/gitlab/cycle_analytics/base_stage.rb
+27
-14
No files found.
lib/gitlab/cycle_analytics/base_event_fetcher.rb
View file @
abca34d0
...
...
@@ -9,7 +9,7 @@ module Gitlab
MAX_EVENTS
=
50
def
initialize
(
project
:,
stage
:,
options
:)
def
initialize
(
project:
nil
,
stage
:,
options
:)
@project
=
project
@stage
=
stage
@options
=
options
...
...
@@ -59,13 +59,17 @@ module Gitlab
def
allowed_ids
@allowed_ids
||=
allowed_ids_finder_class
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
)
.
new
(
@options
[
:current_user
],
allowed_ids_source
)
.
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
def
event_result_ids
event_result
.
map
{
|
event
|
event
[
'id'
]
}
end
def
allowed_ids_source
{
project_id:
@project
.
id
}
end
end
end
end
lib/gitlab/cycle_analytics/base_query.rb
View file @
abca34d0
...
...
@@ -10,7 +10,7 @@ module Gitlab
private
def
base_query
@base_query
||=
stage_query
(
@project
.
id
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@base_query
||=
stage_query
(
projects
.
map
(
&
:id
)
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
stage_query
(
project_ids
)
...
...
lib/gitlab/cycle_analytics/base_stage.rb
View file @
abca34d0
...
...
@@ -5,7 +5,7 @@ module Gitlab
class
BaseStage
include
BaseQuery
def
initialize
(
project
:,
options
:)
def
initialize
(
project:
nil
,
options
:)
@project
=
project
@options
=
options
end
...
...
@@ -14,8 +14,8 @@ module Gitlab
event_fetcher
.
fetch
end
def
as_json
AnalyticsStageS
erializer
.
new
.
represent
(
self
)
def
as_json
(
serializer:
AnalyticsStageSerializer
)
s
erializer
.
new
.
represent
(
self
)
end
def
title
...
...
@@ -24,20 +24,11 @@ module Gitlab
def
median
BatchLoader
.
for
(
@project
.
id
).
batch
(
key:
name
)
do
|
project_ids
,
loader
|
cte_table
=
Arel
::
Table
.
new
(
"cte_table_for_
#{
name
}
"
)
# Build a `SELECT` query. We find the first of the `end_time_attrs` that isn't `NULL` (call this end_time).
# Next, we find the first of the start_time_attrs that isn't `NULL` (call this start_time).
# We compute the (end_time - start_time) interval, and give it an alias based on the current
# cycle analytics stage.
interval_query
=
Arel
::
Nodes
::
As
.
new
(
cte_table
,
subtract_datetimes
(
stage_query
(
project_ids
),
start_time_attrs
,
end_time_attrs
,
name
.
to_s
))
if
project_ids
.
one?
loader
.
call
(
@project
.
id
,
median_
datetime
(
cte_table
,
interval_query
,
name
))
loader
.
call
(
@project
.
id
,
median_
query
(
project_ids
))
else
begin
median_datetimes
(
cte_table
,
interval_query
,
name
,
:project_id
)
&
.
each
do
|
project_id
,
median
|
median_datetimes
(
cte_table
,
interval_query
(
project_ids
)
,
name
,
:project_id
)
&
.
each
do
|
project_id
,
median
|
loader
.
call
(
project_id
,
median
)
end
rescue
NotSupportedError
...
...
@@ -47,10 +38,28 @@ module Gitlab
end
end
def
median_query
(
project_ids
)
# Build a `SELECT` query. We find the first of the `end_time_attrs` that isn't `NULL` (call this end_time).
# Next, we find the first of the start_time_attrs that isn't `NULL` (call this start_time).
# We compute the (end_time - start_time) interval, and give it an alias based on the current
# cycle analytics stage.
median_datetime
(
cte_table
,
interval_query
(
project_ids
),
name
)
end
def
name
raise
NotImplementedError
.
new
(
"Expected
#{
self
.
name
}
to implement name"
)
end
def
cte_table
Arel
::
Table
.
new
(
"cte_table_for_
#{
name
}
"
)
end
def
interval_query
(
project_ids
)
Arel
::
Nodes
::
As
.
new
(
cte_table
,
subtract_datetimes
(
stage_query
(
project_ids
),
start_time_attrs
,
end_time_attrs
,
name
.
to_s
))
end
private
def
event_fetcher
...
...
@@ -62,6 +71,10 @@ module Gitlab
def
event_options
@options
.
merge
(
start_time_attrs:
start_time_attrs
,
end_time_attrs:
end_time_attrs
)
end
def
projects
[
@project
]
end
end
end
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