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
f9eb6c29
Commit
f9eb6c29
authored
Feb 06, 2020
by
Ohad Dahan
Committed by
Douglas Barbosa Alexandre
Feb 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#196250 adding preload to prevent N+1
parent
064696e1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
2 deletions
+51
-2
app/controllers/profiles/notifications_controller.rb
app/controllers/profiles/notifications_controller.rb
+2
-1
app/models/notification_setting.rb
app/models/notification_setting.rb
+2
-0
changelogs/unreleased/196250.yml
changelogs/unreleased/196250.yml
+5
-0
spec/controllers/profiles/notifications_controller_spec.rb
spec/controllers/profiles/notifications_controller_spec.rb
+0
-1
spec/requests/profiles/notifications_controller_spec.rb
spec/requests/profiles/notifications_controller_spec.rb
+42
-0
No files found.
app/controllers/profiles/notifications_controller.rb
View file @
f9eb6c29
...
...
@@ -4,13 +4,14 @@ class Profiles::NotificationsController < Profiles::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def
show
@user
=
current_user
@group_notifications
=
current_user
.
notification_settings
.
for_groups
.
order
(
:id
)
@group_notifications
=
current_user
.
notification_settings
.
preload_source_route
.
for_groups
.
order
(
:id
)
@group_notifications
+=
GroupsFinder
.
new
(
current_user
,
all_available:
false
,
exclude_group_ids:
@group_notifications
.
select
(
:source_id
)
).
execute
.
map
{
|
group
|
current_user
.
notification_settings_for
(
group
,
inherit:
true
)
}
@project_notifications
=
current_user
.
notification_settings
.
for_projects
.
order
(
:id
)
.
preload_source_route
.
select
{
|
notification
|
current_user
.
can?
(
:read_project
,
notification
.
source
)
}
@global_notification_setting
=
current_user
.
global_notification_setting
end
...
...
app/models/notification_setting.rb
View file @
f9eb6c29
...
...
@@ -27,6 +27,8 @@ class NotificationSetting < ApplicationRecord
.
where
.
not
(
projects:
{
pending_delete:
true
})
end
scope
:preload_source_route
,
->
{
preload
(
source:
[
:route
])
}
EMAIL_EVENTS
=
[
:new_release
,
:new_note
,
...
...
changelogs/unreleased/196250.yml
0 → 100644
View file @
f9eb6c29
---
title
:
Remove N+1 query for profile notifications
merge_request
:
22845
author
:
Ohad Dahan
type
:
performance
spec/controllers/profiles/notifications_controller_spec.rb
View file @
f9eb6c29
...
...
@@ -24,7 +24,6 @@ describe Profiles::NotificationsController do
context
'with groups that do not have notification preferences'
do
set
(
:group
)
{
create
(
:group
)
}
set
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
before
do
group
.
add_developer
(
user
)
end
...
...
spec/requests/profiles/notifications_controller_spec.rb
0 → 100644
View file @
f9eb6c29
# frozen_string_literal: true
require
'spec_helper'
describe
'view user notifications'
do
let
(
:user
)
do
create
(
:user
)
do
|
user
|
user
.
emails
.
create
(
email:
'original@example.com'
)
user
.
emails
.
create
(
email:
'new@example.com'
)
user
.
notification_email
=
'original@example.com'
user
.
save!
end
end
before
do
login_as
(
user
)
create_list
(
:group
,
2
)
do
|
group
|
group
.
add_developer
(
user
)
end
end
def
get_profile_notifications
get
profile_notifications_path
end
describe
'GET /profile/notifications'
do
it
'avoid N+1 due to an additional groups (with no parent group)'
do
get_profile_notifications
control
=
ActiveRecord
::
QueryRecorder
.
new
do
get_profile_notifications
end
create_list
(
:group
,
2
)
{
|
group
|
group
.
add_developer
(
user
)
}
expect
do
get_profile_notifications
end
.
not_to
exceed_query_limit
(
control
)
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