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
Jérome Perrin
gitlab-ce
Commits
470e39d6
Commit
470e39d6
authored
Oct 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - refactored some arel queries
parent
ec7db295
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
19 deletions
+31
-19
lib/gitlab/cycle_analytics/events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+12
-5
lib/gitlab/cycle_analytics/metrics_fetcher.rb
lib/gitlab/cycle_analytics/metrics_fetcher.rb
+1
-1
lib/gitlab/database/date_time.rb
lib/gitlab/database/date_time.rb
+15
-11
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+3
-2
No files found.
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
470e39d6
...
...
@@ -11,14 +11,21 @@ module Gitlab
def
fetch_issues
cte_table
=
Arel
::
Table
.
new
(
"cte_table_for_issue"
)
interval_query
=
Arel
::
Nodes
::
As
.
new
(
cte_table
,
subtract_datetimes
(
base_query_for
(
:issue
),
*
attributes
,
'issue'
))
# 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.
#TODO ActiveRecord::Base.connection.execute(interval_query)
base_query
=
base_query_for
(
:issue
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
issue_table
[
:created_at
],
metric_attributes
)
query
=
base_query
.
project
(
diff_fn
.
as
(
'issue_diff'
))
ActiveRecord
::
Base
.
connection
.
execute
(
query
.
to_sql
)
end
def
attributes
def
metric_
attributes
[
issue_metrics_table
[
:first_associated_with_milestone_at
],
issue_metrics_table
[
:first_added_to_board_at
]]
end
...
...
lib/gitlab/cycle_analytics/metrics_fetcher.rb
View file @
470e39d6
...
...
@@ -28,7 +28,7 @@ module Gitlab
# automatically excluded.
def
base_query_for
(
name
)
# Load issues
query
=
issue_metric
s_table
.
join
(
issue_table
).
on
(
issue_table
[
:id
].
eq
(
mr_closing_issues_table
[
:issue_id
])).
query
=
mr_closing_issue
s_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
])).
where
(
issue_table
[
:project_id
].
eq
(
@project
.
id
)).
where
(
issue_table
[
:deleted_at
].
eq
(
nil
)).
...
...
lib/gitlab/database/date_time.rb
View file @
470e39d6
...
...
@@ -8,20 +8,24 @@ module Gitlab
# Note: For MySQL, the interval is returned in seconds.
# For PostgreSQL, the interval is returned as an INTERVAL type.
def
subtract_datetimes
(
query_so_far
,
end_time_attrs
,
start_time_attrs
,
as
)
diff_fn
=
if
Gitlab
::
Database
.
postgresql?
Arel
::
Nodes
::
Subtraction
.
new
(
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)))
elsif
Gitlab
::
Database
.
mysql?
Arel
::
Nodes
::
NamedFunction
.
new
(
"TIMESTAMPDIFF"
,
[
Arel
.
sql
(
'second'
),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
))])
end
diff_fn
=
subtract_datetimes_diff
(
query_so_far
,
end_time_attrs
,
start_time_attrs
)
query_so_far
.
project
(
diff_fn
.
as
(
as
))
end
def
subtract_datetimes_diff
(
query_so_far
,
end_time_attrs
,
start_time_attrs
)
if
Gitlab
::
Database
.
postgresql?
Arel
::
Nodes
::
Subtraction
.
new
(
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)))
elsif
Gitlab
::
Database
.
mysql?
Arel
::
Nodes
::
NamedFunction
.
new
(
"TIMESTAMPDIFF"
,
[
Arel
.
sql
(
'second'
),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
))])
end
end
end
end
end
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
470e39d6
...
...
@@ -15,12 +15,13 @@ describe Gitlab::CycleAnalytics::Events do
let!
(
:context
)
{
create
(
:issue
,
project:
project
)
}
xit
'does something'
do
expect
(
subject
.
issue_events
).
to
eq
([])
expect
(
subject
.
issue_events
).
to
eq
([
context
])
end
end
def
setup
(
context
)
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
context
.
update
(
milestone:
milestone
)
create_merge_request_closing_issue
(
context
)
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