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
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
Show 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
...
@@ -11,14 +11,21 @@ module Gitlab
def
fetch_issues
def
fetch_issues
cte_table
=
Arel
::
Table
.
new
(
"cte_table_for_issue"
)
cte_table
=
Arel
::
Table
.
new
(
"cte_table_for_issue"
)
interval_query
=
Arel
::
Nodes
::
As
.
new
(
# Build a `SELECT` query. We find the first of the `end_time_attrs` that isn't `NULL` (call this end_time).
cte_table
,
# Next, we find the first of the start_time_attrs that isn't `NULL` (call this start_time).
subtract_datetimes
(
base_query_for
(
:issue
),
*
attributes
,
'issue'
))
# 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
end
def
attributes
def
metric_
attributes
[
issue_metrics_table
[
:first_associated_with_milestone_at
],
[
issue_metrics_table
[
:first_associated_with_milestone_at
],
issue_metrics_table
[
:first_added_to_board_at
]]
issue_metrics_table
[
:first_added_to_board_at
]]
end
end
...
...
lib/gitlab/cycle_analytics/metrics_fetcher.rb
View file @
470e39d6
...
@@ -28,7 +28,7 @@ module Gitlab
...
@@ -28,7 +28,7 @@ module Gitlab
# automatically excluded.
# automatically excluded.
def
base_query_for
(
name
)
def
base_query_for
(
name
)
# Load issues
# 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
])).
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
[
:project_id
].
eq
(
@project
.
id
)).
where
(
issue_table
[
:deleted_at
].
eq
(
nil
)).
where
(
issue_table
[
:deleted_at
].
eq
(
nil
)).
...
...
lib/gitlab/database/date_time.rb
View file @
470e39d6
...
@@ -8,7 +8,13 @@ module Gitlab
...
@@ -8,7 +8,13 @@ module Gitlab
# Note: For MySQL, the interval is returned in seconds.
# Note: For MySQL, the interval is returned in seconds.
# For PostgreSQL, the interval is returned as an INTERVAL type.
# For PostgreSQL, the interval is returned as an INTERVAL type.
def
subtract_datetimes
(
query_so_far
,
end_time_attrs
,
start_time_attrs
,
as
)
def
subtract_datetimes
(
query_so_far
,
end_time_attrs
,
start_time_attrs
,
as
)
diff_fn
=
if
Gitlab
::
Database
.
postgresql?
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
::
Subtraction
.
new
(
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)))
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)))
...
@@ -19,8 +25,6 @@ module Gitlab
...
@@ -19,8 +25,6 @@ module Gitlab
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
start_time_attrs
)),
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
))])
Arel
::
Nodes
::
NamedFunction
.
new
(
"COALESCE"
,
Array
.
wrap
(
end_time_attrs
))])
end
end
query_so_far
.
project
(
diff_fn
.
as
(
as
))
end
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
...
@@ -15,12 +15,13 @@ describe Gitlab::CycleAnalytics::Events do
let!
(
:context
)
{
create
(
:issue
,
project:
project
)
}
let!
(
:context
)
{
create
(
:issue
,
project:
project
)
}
xit
'does something'
do
xit
'does something'
do
expect
(
subject
.
issue_events
).
to
eq
([])
expect
(
subject
.
issue_events
).
to
eq
([
context
])
end
end
end
end
def
setup
(
context
)
def
setup
(
context
)
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
context
.
update
(
milestone:
milestone
)
create_merge_request_closing_issue
(
context
)
create_merge_request_closing_issue
(
context
)
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