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
073e579a
Commit
073e579a
authored
Feb 22, 2022
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix false-positive N+1 tests
parent
400bcbc9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
ee/spec/serializers/ee/environment_serializer_spec.rb
ee/spec/serializers/ee/environment_serializer_spec.rb
+2
-2
spec/support/shared_examples/serializers/environment_serializer_shared_examples.rb
...les/serializers/environment_serializer_shared_examples.rb
+13
-4
No files found.
ee/spec/serializers/ee/environment_serializer_spec.rb
View file @
073e579a
...
...
@@ -11,10 +11,10 @@ RSpec.describe EE::EnvironmentSerializer do
end
before
do
stub_licensed_features
(
environment_alerts:
true
)
stub_licensed_features
(
environment_alerts:
true
,
protected_environments:
true
)
end
it_behaves_like
'avoid N+1 on environments serialization'
it_behaves_like
'avoid N+1 on environments serialization'
,
ee:
true
def
create_environment_with_associations
(
project
)
create
(
:environment
,
project:
project
).
tap
do
|
environment
|
...
...
spec/support/shared_examples/serializers/environment_serializer_shared_examples.rb
View file @
073e579a
# frozen_string_literal: true
RSpec
.
shared_examples
'avoid N+1 on environments serialization'
do
RSpec
.
shared_examples
'avoid N+1 on environments serialization'
do
|
ee:
false
|
# Investigating in https://gitlab.com/gitlab-org/gitlab/-/issues/353209
let
(
:query_threshold
)
{
50
+
(
ee
?
4
:
0
)
}
it
'avoids N+1 database queries with grouping'
,
:request_store
do
create_environment_with_associations
(
project
)
control
=
ActiveRecord
::
QueryRecorder
.
new
{
serialize
(
grouping:
true
)
}
create_environment_with_associations
(
project
)
create_environment_with_associations
(
project
)
expect
{
serialize
(
grouping:
true
)
}.
not_to
exceed_query_limit
(
control
.
count
)
expect
{
serialize
(
grouping:
true
)
}
.
not_to
exceed_query_limit
(
control
.
count
)
.
with_threshold
(
query_threshold
)
end
it
'avoids N+1 database queries without grouping'
,
:request_store
do
...
...
@@ -15,9 +21,12 @@ RSpec.shared_examples 'avoid N+1 on environments serialization' do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
serialize
(
grouping:
false
)
}
create_environment_with_associations
(
project
)
create_environment_with_associations
(
project
)
expect
{
serialize
(
grouping:
false
)
}.
not_to
exceed_query_limit
(
control
.
count
)
expect
{
serialize
(
grouping:
false
)
}
.
not_to
exceed_query_limit
(
control
.
count
)
.
with_threshold
(
query_threshold
)
end
it
'does not preload for environments that does not exist in the page'
,
:request_store
do
...
...
@@ -35,7 +44,7 @@ RSpec.shared_examples 'avoid N+1 on environments serialization' do
end
def
serialize
(
grouping
:,
query:
nil
)
query
||=
{
page:
1
,
per_page:
1
}
query
||=
{
page:
1
,
per_page:
20
}
request
=
double
(
url:
"
#{
Gitlab
.
config
.
gitlab
.
url
}
:8080/api/v4/projects?
#{
query
.
to_query
}
"
,
query_parameters:
query
)
EnvironmentSerializer
.
new
(
current_user:
user
,
project:
project
).
yield_self
do
|
serializer
|
...
...
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