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
0a12fb6a
Commit
0a12fb6a
authored
Mar 02, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
7b3ad26f
c1b50f85
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
3 deletions
+37
-3
changelogs/unreleased/sh-optimize-calendar-activities.yml
changelogs/unreleased/sh-optimize-calendar-activities.yml
+5
-0
lib/gitlab/contributions_calendar.rb
lib/gitlab/contributions_calendar.rb
+1
-0
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+31
-3
No files found.
changelogs/unreleased/sh-optimize-calendar-activities.yml
0 → 100644
View file @
0a12fb6a
---
title
:
Eliminate most N+1 queries loading UserController#calendar_activities
merge_request
:
25697
author
:
type
:
performance
lib/gitlab/contributions_calendar.rb
View file @
0a12fb6a
...
...
@@ -49,6 +49,7 @@ module Gitlab
Event
.
contributions
.
where
(
author_id:
contributor
.
id
)
.
where
(
created_at:
date
.
beginning_of_day
..
date
.
end_of_day
)
.
where
(
project_id:
projects
)
.
with_associations
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
spec/controllers/users_controller_spec.rb
View file @
0a12fb6a
...
...
@@ -185,13 +185,32 @@ describe UsersController do
context
'for user'
do
context
'with public profile'
do
it
'renders calendar_activities'
do
push_data
=
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
public_user
)
EventCreateService
.
new
.
push
(
project
,
public_user
,
push_data
)
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
user
)
}
let
(
:note
)
{
create
(
:note
,
noteable:
issue
,
author:
user
,
project:
project
)
}
render_views
before
do
create_push_event
create_note_event
end
it
'renders calendar_activities'
do
get
:calendar_activities
,
params:
{
username:
public_user
.
username
}
expect
(
assigns
[
:events
]).
not_to
be_empty
end
it
'avoids N+1 queries'
,
:request_store
do
get
:calendar_activities
,
params:
{
username:
public_user
.
username
}
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get
:calendar_activities
,
params:
{
username:
public_user
.
username
}
}
create_push_event
create_note_event
expect
{
get
:calendar_activities
,
params:
{
username:
public_user
.
username
}
}.
not_to
exceed_query_limit
(
control
)
end
end
context
'with private profile'
do
...
...
@@ -203,6 +222,15 @@ describe UsersController do
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
def
create_push_event
push_data
=
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
public_user
)
EventCreateService
.
new
.
push
(
project
,
public_user
,
push_data
)
end
def
create_note_event
EventCreateService
.
new
.
leave_note
(
note
,
public_user
)
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