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
e1dad9f6
Commit
e1dad9f6
authored
Jul 11, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 queries when loading vulnerablity feedback
Use Vulnerabilities::OccurrencesPreloader for API requests
parent
a02dcee4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
5 deletions
+29
-5
ee/changelogs/unreleased/fix-vulnerability-feeback-n-plus-1.yml
...ngelogs/unreleased/fix-vulnerability-feeback-n-plus-1.yml
+5
-0
ee/lib/api/vulnerabilities.rb
ee/lib/api/vulnerabilities.rb
+7
-3
ee/lib/gitlab/vulnerabilities/occurrences_preloader.rb
ee/lib/gitlab/vulnerabilities/occurrences_preloader.rb
+9
-2
ee/spec/requests/api/vulnerabilities_spec.rb
ee/spec/requests/api/vulnerabilities_spec.rb
+8
-0
No files found.
ee/changelogs/unreleased/fix-vulnerability-feeback-n-plus-1.yml
0 → 100644
View file @
e1dad9f6
---
title
:
Fix N+1 queries in vulnerabilities API
merge_request
:
14638
author
:
type
:
performance
ee/lib/api/vulnerabilities.rb
View file @
e1dad9f6
...
...
@@ -50,11 +50,15 @@ module API
get
':id/vulnerabilities'
do
authorize!
:read_project_security_dashboard
,
user_project
vulnerability_occurrences
=
Kaminari
.
paginate_array
(
vulnerability_occurrences_by
(
declared_params
.
merge
(
project:
user_project
))
vulnerability_occurrences
=
paginate
(
Kaminari
.
paginate_array
(
vulnerability_occurrences_by
(
declared_params
.
merge
(
project:
user_project
))
)
)
present
paginate
(
vulnerability_occurrences
),
Gitlab
::
Vulnerabilities
::
OccurrencesPreloader
.
preload_feedback!
(
vulnerability_occurrences
)
present
vulnerability_occurrences
,
with:
::
Vulnerabilities
::
OccurrenceEntity
,
request:
GrapeRequestProxy
.
new
(
request
,
current_user
)
end
...
...
ee/lib/gitlab/vulnerabilities/occurrences_preloader.rb
View file @
e1dad9f6
...
...
@@ -9,8 +9,15 @@ module Gitlab
class
OccurrencesPreloader
def
self
.
preload!
(
occurrences
)
occurrences
.
all_preloaded
.
tap
do
|
occurrences
|
occurrences
.
each
(
&
:issue_feedback
)
occurrences
.
each
(
&
:dismissal_feedback
)
preload_feedback!
(
occurrences
)
end
end
def
self
.
preload_feedback!
(
occurrences
)
occurrences
.
each
do
|
occurrence
|
occurrence
.
dismissal_feedback
occurrence
.
issue_feedback
occurrence
.
merge_request_feedback
end
end
end
...
...
ee/spec/requests/api/vulnerabilities_spec.rb
View file @
e1dad9f6
...
...
@@ -52,6 +52,14 @@ describe API::Vulnerabilities do
expect
(
json_response
.
map
{
|
v
|
v
[
'report_type'
]
}.
uniq
).
to
match_array
%w[dependency_scanning sast]
end
it
'does not have N+1 queries'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
get
api
(
"/projects/
#{
project
.
id
}
/vulnerabilities"
,
user
),
params:
{
report_type:
'dependency_scanning'
}
end
.
count
expect
{
get
api
(
"/projects/
#{
project
.
id
}
/vulnerabilities"
,
user
)
}.
not_to
exceed_query_limit
(
control_count
)
end
describe
'filtering'
do
it
'returns vulnerabilities with sast report_type'
do
occurrence_count
=
(
sast_report
.
occurrences
.
count
-
1
).
to_s
...
...
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