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
7ed0806a
Commit
7ed0806a
authored
Oct 01, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cached queries to the performance bar
parent
2aaa1509
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
8 deletions
+33
-8
app/assets/javascripts/performance_bar/components/performance_bar_app.vue
...cripts/performance_bar/components/performance_bar_app.vue
+1
-1
lib/peek/views/active_record.rb
lib/peek/views/active_record.rb
+32
-7
spec/lib/peek/views/active_record_spec.rb
spec/lib/peek/views/active_record_spec.rb
+0
-0
No files found.
app/assets/javascripts/performance_bar/components/performance_bar_app.vue
View file @
7ed0806a
...
...
@@ -36,7 +36,7 @@ export default {
metric
:
'
active-record
'
,
title
:
'
pg
'
,
header
:
s__
(
'
PerformanceBar|SQL queries
'
),
keys
:
[
'
sql
'
],
keys
:
[
'
sql
'
,
'
cached
'
],
},
{
metric
:
'
bullet
'
,
...
...
lib/peek/views/active_record.rb
View file @
7ed0806a
...
...
@@ -5,6 +5,7 @@ module Peek
class
ActiveRecord
<
DetailedView
DEFAULT_THRESHOLDS
=
{
calls:
100
,
cached_calls:
100
,
duration:
3000
,
individual_call:
1000
}.
freeze
...
...
@@ -12,29 +13,53 @@ module Peek
THRESHOLDS
=
{
production:
{
calls:
100
,
cached_calls:
100
,
duration:
15000
,
individual_call:
5000
}
}.
freeze
def
results
super
.
merge
(
calls:
detailed_calls
)
end
def
self
.
thresholds
@thresholds
||=
THRESHOLDS
.
fetch
(
Rails
.
env
.
to_sym
,
DEFAULT_THRESHOLDS
)
end
private
def
detailed_calls
cached_calls?
?
"
#{
calls
}
|
#{
cached_calls
}
"
:
calls
end
def
calls
super
-
cached_calls
end
def
cached_calls
detail_store
.
count
{
|
item
|
item
[
:cached
]
==
'cached'
}
end
def
cached_calls?
detail_store
.
any?
{
|
item
|
item
[
:cached
]
==
'cached'
}
end
def
warnings
(
super
+
warning_for
(
cached_calls
,
self
.
class
.
thresholds
[
:cached_calls
],
label:
"
#{
key
}
cached calls"
)).
compact
end
def
setup_subscribers
super
subscribe
(
'sql.active_record'
)
do
|
_
,
start
,
finish
,
_
,
data
|
if
Gitlab
::
PerformanceBar
.
enabled_for_request?
unless
data
[
:cached
]
detail_store
<<
{
duration:
finish
-
start
,
sql:
data
[
:sql
].
strip
,
backtrace:
Gitlab
::
BacktraceCleaner
.
clean_backtrace
(
caller
)
}
end
detail_store
<<
{
duration:
finish
-
start
,
sql:
data
[
:sql
].
strip
,
backtrace:
Gitlab
::
BacktraceCleaner
.
clean_backtrace
(
caller
),
cached:
data
[
:cached
]
?
'cached'
:
''
}
end
end
end
...
...
spec/lib/peek/views/active_record_spec.rb
0 → 100644
View file @
7ed0806a
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