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
Boxiang Sun
gitlab-ce
Commits
819ecd5f
Commit
819ecd5f
authored
Oct 02, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 for notification recipients in subscribers
parent
eac20b74
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
15 deletions
+40
-15
app/models/concerns/subscribable.rb
app/models/concerns/subscribable.rb
+5
-3
spec/services/notification_recipient_service_spec.rb
spec/services/notification_recipient_service_spec.rb
+35
-12
No files found.
app/models/concerns/subscribable.rb
View file @
819ecd5f
...
@@ -31,9 +31,11 @@ module Subscribable
...
@@ -31,9 +31,11 @@ module Subscribable
end
end
def
subscribers
(
project
)
def
subscribers
(
project
)
subscriptions_available
(
project
)
relation
=
subscriptions_available
(
project
)
.
where
(
subscribed:
true
)
.
where
(
subscribed:
true
)
.
map
(
&
:user
)
.
select
(
:user_id
)
User
.
where
(
id:
relation
)
end
end
def
toggle_subscription
(
user
,
project
=
nil
)
def
toggle_subscription
(
user
,
project
=
nil
)
...
...
spec/services/notification_recipient_service_spec.rb
View file @
819ecd5f
...
@@ -10,6 +10,7 @@ describe NotificationRecipientService do
...
@@ -10,6 +10,7 @@ describe NotificationRecipientService do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
assignees:
[
assignee
])
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
assignees:
[
assignee
])
}
let
(
:note
)
{
create
(
:note_on_issue
,
noteable:
issue
,
project_id:
issue
.
project_id
)
}
let
(
:note
)
{
create
(
:note_on_issue
,
noteable:
issue
,
project_id:
issue
.
project_id
)
}
context
'when there are multiple watchers'
do
def
create_watcher
def
create_watcher
watcher
=
create
(
:user
)
watcher
=
create
(
:user
)
create
(
:notification_setting
,
source:
project
,
user:
watcher
,
level: :watch
)
create
(
:notification_setting
,
source:
project
,
user:
watcher
,
level: :watch
)
...
@@ -33,4 +34,26 @@ describe NotificationRecipientService do
...
@@ -33,4 +34,26 @@ describe NotificationRecipientService do
expect
{
service
.
build_new_note_recipients
(
note
)
}.
not_to
exceed_query_limit
(
control_count
)
expect
{
service
.
build_new_note_recipients
(
note
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
end
end
context
'when there are multiple subscribers'
do
def
create_subscriber
subscriber
=
create
(
:user
)
issue
.
subscriptions
.
create
(
user:
subscriber
,
project:
project
,
subscribed:
true
)
end
it
'avoids N+1 queries'
do
create_subscriber
service
.
build_new_note_recipients
(
note
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
service
.
build_new_note_recipients
(
note
)
end
create_subscriber
expect
{
service
.
build_new_note_recipients
(
note
)
}.
not_to
exceed_query_limit
(
control_count
)
end
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