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
3d4ba90c
Commit
3d4ba90c
authored
Dec 04, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Count occurrences of a specific query in the query recorder.
parent
20f78421
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
11 deletions
+18
-11
spec/controllers/projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+4
-6
spec/support/query_recorder.rb
spec/support/query_recorder.rb
+14
-5
No files found.
spec/controllers/projects_controller_spec.rb
View file @
3d4ba90c
...
@@ -264,24 +264,22 @@ describe ProjectsController do
...
@@ -264,24 +264,22 @@ describe ProjectsController do
context
'when the project is forked and has a repository'
,
:request_store
do
context
'when the project is forked and has a repository'
,
:request_store
do
let
(
:public_project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:public_project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:other_user
)
{
create
(
:user
)
}
render_views
render_views
before
do
before
do
# View the project as a user that does not have any rights
# View the project as a user that does not have any rights
sign_in
(
create
(
:user
)
)
sign_in
(
other_user
)
fork_project
(
public_project
)
fork_project
(
public_project
)
end
end
it
'does not increase the number of queries when the project is forked'
do
it
'does not increase the number of queries when the project is forked'
do
# When a project is part of a fork network, we check if the `current_user`
expected_query
=
/
#{
public_project
.
fork_network
.
find_forks_in
(
other_user
.
namespace
).
to_sql
}
/
# has a fork in their own namespace. We query this several times. Caching
# the result in the RequestStore brings the number of queries for this
# request down from 64 to 59.
expect
{
get
(
:show
,
namespace_id:
public_project
.
namespace
,
id:
public_project
)
}
expect
{
get
(
:show
,
namespace_id:
public_project
.
namespace
,
id:
public_project
)
}
.
not_to
exceed_query_limit
(
59
)
.
not_to
exceed_query_limit
(
1
).
for_query
(
expected_query
)
end
end
end
end
end
end
...
...
spec/support/query_recorder.rb
View file @
3d4ba90c
...
@@ -41,7 +41,8 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
...
@@ -41,7 +41,8 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
supports_block_expectations
supports_block_expectations
match
do
|
block
|
match
do
|
block
|
query_count
(
&
block
)
>
expected_count
+
threshold
@subject_block
=
block
actual_count
>
expected_count
+
threshold
end
end
failure_message_when_negated
do
|
actual
|
failure_message_when_negated
do
|
actual
|
...
@@ -55,6 +56,11 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
...
@@ -55,6 +56,11 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
self
self
end
end
def
for_query
(
query
)
@query
=
query
self
end
def
threshold
def
threshold
@threshold
.
to_i
@threshold
.
to_i
end
end
...
@@ -68,12 +74,15 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
...
@@ -68,12 +74,15 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
end
end
def
actual_count
def
actual_count
@recorder
.
count
@actual_count
||=
if
@query
recorder
.
log
.
select
{
|
recorded
|
recorded
=~
@query
}.
size
else
recorder
.
count
end
end
end
def
query_count
(
&
block
)
def
recorder
@recorder
=
ActiveRecord
::
QueryRecorder
.
new
(
&
block
)
@recorder
||=
ActiveRecord
::
QueryRecorder
.
new
(
&
@subject_block
)
@recorder
.
count
end
end
def
count_queries
(
queries
)
def
count_queries
(
queries
)
...
...
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