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
40956c78
Commit
40956c78
authored
Feb 14, 2018
by
Greg Stark
Committed by
Stan Hu
Jan 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize SQL to replace N+1 in Groups:Analytics#show
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
025ed5a1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
7 deletions
+26
-7
app/models/push_event_payload.rb
app/models/push_event_payload.rb
+2
-0
ee/app/models/ee/push_event_payload.rb
ee/app/models/ee/push_event_payload.rb
+13
-0
ee/app/views/groups/analytics/show.html.haml
ee/app/views/groups/analytics/show.html.haml
+1
-1
ee/changelogs/unreleased/index-for-groups-analytic-controller-4899.yml
.../unreleased/index-for-groups-analytic-controller-4899.yml
+5
-0
ee/spec/controllers/groups/analytics_controller_spec.rb
ee/spec/controllers/groups/analytics_controller_spec.rb
+5
-6
No files found.
app/models/push_event_payload.rb
View file @
40956c78
...
...
@@ -22,3 +22,5 @@ class PushEventPayload < ActiveRecord::Base
tag:
1
}
end
PushEventPayload
.
prepend
(
EE
::
PushEventPayload
)
ee/app/models/ee/push_event_payload.rb
0 → 100644
View file @
40956c78
# frozen_string_literal: true
module
EE
module
PushEventPayload
extend
ActiveSupport
::
Concern
class_methods
do
def
commit_count_for
(
events
)
where
(
event_id:
events
).
sum
(
:commit_count
)
end
end
end
end
ee/app/views/groups/analytics/show.html.haml
View file @
40956c78
...
...
@@ -22,7 +22,7 @@
%h3
Push
-
code_push_count
=
@events
.
code_push
.
count
-
commits_count
=
@events
.
code_push
.
map
(
&
:commits_count
).
sum
# rubocop: disable CodeReuse/ActiveRecord
-
commits_count
=
PushEventPayload
.
commit_count_for
(
@events
.
code_push
)
-
person_count
=
@events
.
code_push
.
pluck
(
:author_id
).
uniq
.
count
# rubocop: disable CodeReuse/ActiveRecord
-
person_count_string
=
pluralize
person_count
,
'person'
-
pushes_string
=
_
(
'<strong>%{pushes}</strong> pushes, more than <strong>%{commits}</strong> commits by <strong>%{people}</strong> contributors.'
).
html_safe
%
{
pushes:
code_push_count
,
commits:
commits_count
,
people:
person_count_string
}
...
...
ee/changelogs/unreleased/index-for-groups-analytic-controller-4899.yml
0 → 100644
View file @
40956c78
---
title
:
Solve a N+1 issue in Groups::AnalyticsController
merge_request
:
4508
author
:
type
:
performance
ee/spec/controllers/groups/analytics_controller_spec.rb
View file @
40956c78
...
...
@@ -111,14 +111,13 @@ describe Groups::AnalyticsController do
render_views
it
'avoids a N+1 query in #show'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get
:show
,
params:
{
group_id:
group
.
path
}
}.
count
# Warm the cache
get
:show
,
params:
{
group_id:
group
.
path
}
# Clear out controller state to force a refresh of the group
controller
.
instance_variable_set
(
:@group
,
nil
)
user4
=
create
(
:user
)
group
.
add_user
(
user4
,
GroupMember
::
DEVELOPER
)
control_queries
=
ActiveRecord
::
QueryRecorder
.
new
{
get
:show
,
params:
{
group_id:
group
.
path
}
}
create_push_event
(
user
,
project
)
expect
{
get
:show
,
params:
{
group_id:
group
.
path
}
}.
not_to
exceed_query_limit
(
control_
count
)
expect
{
get
:show
,
params:
{
group_id:
group
.
path
}
}.
not_to
exceed_query_limit
(
control_
queries
)
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