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
2e216dd4
Commit
2e216dd4
authored
Feb 21, 2018
by
Dylan Griffith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not count rails sql cache as queries in query limiting
parent
11bf575f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
10 deletions
+27
-10
lib/gitlab/query_limiting/active_support_subscriber.rb
lib/gitlab/query_limiting/active_support_subscriber.rb
+4
-2
spec/lib/gitlab/query_limiting/active_support_subscriber_spec.rb
...b/gitlab/query_limiting/active_support_subscriber_spec.rb
+23
-8
No files found.
lib/gitlab/query_limiting/active_support_subscriber.rb
View file @
2e216dd4
...
@@ -3,9 +3,11 @@ module Gitlab
...
@@ -3,9 +3,11 @@ module Gitlab
class
ActiveSupportSubscriber
<
ActiveSupport
::
Subscriber
class
ActiveSupportSubscriber
<
ActiveSupport
::
Subscriber
attach_to
:active_record
attach_to
:active_record
def
sql
(
*
)
def
sql
(
event
)
unless
event
.
payload
[
:name
]
==
'CACHE'
Transaction
.
current
&
.
increment
Transaction
.
current
&
.
increment
end
end
end
end
end
end
end
end
end
spec/lib/gitlab/query_limiting/active_support_subscriber_spec.rb
View file @
2e216dd4
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
QueryLimiting
::
ActiveSupportSubscriber
do
describe
Gitlab
::
QueryLimiting
::
ActiveSupportSubscriber
do
describe
'#sql'
do
let
(
:transaction
)
{
instance_double
(
Gitlab
::
QueryLimiting
::
Transaction
,
increment:
true
)
}
it
'increments the number of executed SQL queries'
do
transaction
=
double
(
:transaction
)
before
do
allow
(
Gitlab
::
QueryLimiting
::
Transaction
)
allow
(
Gitlab
::
QueryLimiting
::
Transaction
)
.
to
receive
(
:current
)
.
to
receive
(
:current
)
.
and_return
(
transaction
)
.
and_return
(
transaction
)
end
describe
'#sql'
do
it
'increments the number of executed SQL queries'
do
User
.
count
expect
(
transaction
)
expect
(
transaction
)
.
to
receive
(
:increment
)
.
to
have_received
(
:increment
)
.
at_least
(
:once
)
.
once
end
context
'when the query is actually a rails cache hit'
do
it
'does not increment the number of executed SQL queries'
do
ActiveRecord
::
Base
.
connection
.
cache
do
User
.
count
User
.
count
User
.
count
end
end
expect
(
transaction
)
.
to
have_received
(
:increment
)
.
once
end
end
end
end
end
end
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