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
512c8f3c
Commit
512c8f3c
authored
Aug 07, 2020
by
Alan (Maciej) Paruszewski
Committed by
Sean McGivern
Aug 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload vulnerability statistics when loading vulnerable projects
parent
406070f5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
1 deletion
+13
-1
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+1
-0
ee/app/models/vulnerabilities/projects_grade.rb
ee/app/models/vulnerabilities/projects_grade.rb
+1
-1
ee/changelogs/unreleased/233536-resolve-n-1-queries-when-loading-statistics.yml
...ed/233536-resolve-n-1-queries-when-loading-statistics.yml
+5
-0
ee/spec/models/vulnerabilities/projects_grade_spec.rb
ee/spec/models/vulnerabilities/projects_grade_spec.rb
+6
-0
No files found.
ee/app/models/ee/project.rb
View file @
512c8f3c
...
...
@@ -151,6 +151,7 @@ module EE
scope
:with_compliance_framework_settings
,
->
{
preload
(
:compliance_framework_setting
)
}
scope
:has_vulnerabilities
,
->
{
joins
(
:vulnerabilities
).
group
(
:id
)
}
scope
:has_vulnerability_statistics
,
->
{
joins
(
:vulnerability_statistic
)
}
scope
:with_vulnerability_statistics
,
->
{
includes
(
:vulnerability_statistic
)
}
scope
:with_group_saml_provider
,
->
{
preload
(
group: :saml_provider
)
}
...
...
ee/app/models/vulnerabilities/projects_grade.rb
View file @
512c8f3c
...
...
@@ -16,7 +16,7 @@ module Vulnerabilities
def
projects
return
vulnerable
.
projects
.
none
if
project_ids
.
blank?
vulnerable
.
projects
.
where
(
id:
project_ids
)
vulnerable
.
projects
.
w
ith_vulnerability_statistics
.
inc_routes
.
w
here
(
id:
project_ids
)
end
def
self
.
grades_for
(
vulnerables
)
...
...
ee/changelogs/unreleased/233536-resolve-n-1-queries-when-loading-statistics.yml
0 → 100644
View file @
512c8f3c
---
title
:
Preload vulnerability statistics when loading vulnerable projects
merge_request
:
38905
author
:
type
:
performance
ee/spec/models/vulnerabilities/projects_grade_spec.rb
View file @
512c8f3c
...
...
@@ -78,6 +78,12 @@ RSpec.describe Vulnerabilities::ProjectsGrade do
subject
(
:projects
)
{
projects_grade
.
projects
}
it
{
is_expected
.
to
match_array
(
expected_projects
)
}
it
'preloads vulnerability statistic once for whole collection'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
new
(
group
,
1
,
[
project_3
.
id
]).
projects
.
map
(
&
:vulnerability_statistic
)
}.
count
expect
{
described_class
.
new
(
group
,
1
,
[
project_3
.
id
,
project_4
.
id
]).
projects
.
map
(
&
:vulnerability_statistic
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
describe
'#count'
do
...
...
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