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
Léo-Paul Géneau
gitlab-ce
Commits
98773ef9
Commit
98773ef9
authored
Nov 17, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
preload ids or objects for users, merge request and issues
parent
de96f295
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
19 deletions
+56
-19
lib/gitlab/cycle_analytics/author_updater.rb
lib/gitlab/cycle_analytics/author_updater.rb
+27
-0
lib/gitlab/cycle_analytics/base_event.rb
lib/gitlab/cycle_analytics/base_event.rb
+21
-3
lib/gitlab/cycle_analytics/code_event.rb
lib/gitlab/cycle_analytics/code_event.rb
+2
-4
lib/gitlab/cycle_analytics/issue_event.rb
lib/gitlab/cycle_analytics/issue_event.rb
+2
-4
lib/gitlab/cycle_analytics/production_event.rb
lib/gitlab/cycle_analytics/production_event.rb
+2
-4
lib/gitlab/cycle_analytics/review_event.rb
lib/gitlab/cycle_analytics/review_event.rb
+2
-4
No files found.
lib/gitlab/cycle_analytics/author_updater.rb
0 → 100644
View file @
98773ef9
module
Gitlab
module
CycleAnalytics
class
AuthorUpdater
def
self
.
update!
(
*
args
)
new
(
*
args
).
update!
end
def
initialize
(
event_result
)
@event_result
=
event_result
end
def
update!
@event_result
.
each
do
|
event
|
event
[
'author'
]
=
users
[
event
.
delete
(
'author_id'
).
to_i
].
first
end
end
def
user_ids
@event_result
.
map
{
|
event
|
event
[
'author_id'
]
}
end
def
users
@users
||=
User
.
find
(
user_ids
).
group_by
{
|
user
|
user
[
'id'
]
}
end
end
end
end
lib/gitlab/cycle_analytics/base_event.rb
View file @
98773ef9
...
...
@@ -12,7 +12,9 @@ module Gitlab
end
def
fetch
@query
.
execute
(
self
).
map
do
|
event
|
update_author!
if
event_result
.
first
[
'author_id'
]
event_result
.
map
do
|
event
|
serialize
(
event
)
if
has_permission?
(
event
[
'id'
])
end
end
...
...
@@ -25,12 +27,28 @@ module Gitlab
private
def
update_author!
AuthorUpdater
.
update!
(
event_result
)
end
def
event_result
@event_result
||=
@query
.
execute
(
self
).
to_a
end
def
serialize
(
_event
)
raise
NotImplementedError
.
new
(
"Expected
#{
self
.
name
}
to implement serialize(event)"
)
end
def
has_permission?
(
_id
)
true
def
has_permission?
(
id
)
allowed_ids
.
nil?
||
allowed_ids
.
include?
(
id
.
to_i
)
end
def
allowed_ids
nil
end
def
event_result_ids
event_result
.
map
{
|
event
|
event
[
'id'
]
}
end
end
end
...
...
lib/gitlab/cycle_analytics/code_event.rb
View file @
98773ef9
...
...
@@ -19,13 +19,11 @@ module Gitlab
private
def
serialize
(
event
)
event
[
'author'
]
=
User
.
find
(
event
.
delete
(
'author_id'
))
AnalyticsMergeRequestSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
def
has_permission?
(
id
)
@
options
[
:current_user
].
can?
(
:read_merge_request
,
MergeRequest
.
find
(
id
)
)
def
allowed_ids
@
allowed_ids
||=
MergeRequestsFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
...
...
lib/gitlab/cycle_analytics/issue_event.rb
View file @
98773ef9
...
...
@@ -18,13 +18,11 @@ module Gitlab
private
def
serialize
(
event
)
event
[
'author'
]
=
User
.
find
(
event
.
delete
(
'author_id'
))
AnalyticsIssueSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
def
has_permission?
(
id
)
@
options
[
:current_user
].
can?
(
:read_issue
,
Issue
.
find
(
id
)
)
def
allowed_ids
@
allowed_ids
||=
IssuesFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
...
...
lib/gitlab/cycle_analytics/production_event.rb
View file @
98773ef9
...
...
@@ -17,13 +17,11 @@ module Gitlab
private
def
serialize
(
event
)
event
[
'author'
]
=
User
.
find
(
event
.
delete
(
'author_id'
))
AnalyticsIssueSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
def
has_permission?
(
id
)
@
options
[
:current_user
].
can?
(
:read_issue
,
Issue
.
find
(
id
)
)
def
allowed_ids
@
allowed_ids
||=
IssuesFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
...
...
lib/gitlab/cycle_analytics/review_event.rb
View file @
98773ef9
...
...
@@ -16,13 +16,11 @@ module Gitlab
end
def
serialize
(
event
)
event
[
'author'
]
=
User
.
find
(
event
.
delete
(
'author_id'
))
AnalyticsMergeRequestSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
def
has_permission?
(
id
)
@
options
[
:current_user
].
can?
(
:read_merge_request
,
MergeRequest
.
find
(
id
)
)
def
allowed_ids
@
allowed_ids
||=
MergeRequestsFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
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