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
acd04842
Commit
acd04842
authored
Oct 12, 2020
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload user notes count in GraphQL
parent
56934676
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
0 deletions
+29
-0
app/graphql/types/merge_request_type.rb
app/graphql/types/merge_request_type.rb
+12
-0
changelogs/unreleased/batch-load-user-notes-count.yml
changelogs/unreleased/batch-load-user-notes-count.yml
+5
-0
spec/requests/api/graphql/project/merge_requests_spec.rb
spec/requests/api/graphql/project/merge_requests_spec.rb
+12
-0
No files found.
app/graphql/types/merge_request_type.rb
View file @
acd04842
...
...
@@ -159,6 +159,18 @@ module Types
object
.
approved_by_users
end
# rubocop: disable CodeReuse/ActiveRecord
def
user_notes_count
BatchLoader
::
GraphQL
.
for
(
object
.
id
).
batch
(
key: :merge_request_user_notes_count
)
do
|
ids
,
loader
,
args
|
counts
=
Note
.
where
(
noteable_type:
'MergeRequest'
,
noteable_id:
ids
).
user
.
group
(
:noteable_id
).
count
ids
.
each
do
|
id
|
loader
.
call
(
id
,
counts
[
id
]
||
0
)
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
diff_stats
(
path:
nil
)
stats
=
Array
.
wrap
(
object
.
diff_stats
&
.
to_a
)
...
...
changelogs/unreleased/batch-load-user-notes-count.yml
0 → 100644
View file @
acd04842
---
title
:
Preload `user_notes_count` in MergeRequest GraphQL API
merge_request
:
44894
author
:
type
:
performance
spec/requests/api/graphql/project/merge_requests_spec.rb
View file @
acd04842
...
...
@@ -232,7 +232,19 @@ RSpec.describe 'getting merge request listings nested in a project' do
include_examples
'N+1 query check'
end
context
'when requesting `user_notes_count`'
do
let
(
:requested_fields
)
{
[
:user_notes_count
]
}
before
do
create_list
(
:note_on_merge_request
,
2
,
noteable:
merge_request_a
,
project:
project
)
create
(
:note_on_merge_request
,
noteable:
merge_request_c
,
project:
project
)
end
include_examples
'N+1 query check'
end
end
describe
'sorting and pagination'
do
let
(
:data_path
)
{
[
:project
,
:mergeRequests
]
}
...
...
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