summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-07-17 17:15:23 +0000
committerMike Greiling <mike@pixelcog.com>2017-07-20 17:04:18 -0500
commit6cb25252aae3988875aecc26de43f74d42f7cb93 (patch)
tree45a5e4e85bc650d92ab0fc926ee17bd7e1670382
parent33739d3315235699b3840465edc9ba7da2c45f27 (diff)
downloadgitlab-ce-6cb25252aae3988875aecc26de43f74d42f7cb93.tar.gz
Merge branch '34940-peek-performance-bar-doesn-t-count-cached-queries-but-shows-them' into 'master'
Resolve "Peek performance bar doesn't count cached queries, but shows them" Closes #34940 See merge request !12915
-rw-r--r--lib/gitlab/performance_bar/peek_query_tracker.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/gitlab/performance_bar/peek_query_tracker.rb b/lib/gitlab/performance_bar/peek_query_tracker.rb
index 574ae8731a5..f97e895dbd0 100644
--- a/lib/gitlab/performance_bar/peek_query_tracker.rb
+++ b/lib/gitlab/performance_bar/peek_query_tracker.rb
@@ -1,4 +1,5 @@
# Inspired by https://github.com/peek/peek-pg/blob/master/lib/peek/views/pg.rb
+# PEEK_DB_CLIENT is a constant set in config/initializers/peek.rb
module Gitlab
module PerformanceBar
module PeekQueryTracker
@@ -23,7 +24,13 @@ module Gitlab
subscribe('sql.active_record') do |_, start, finish, _, data|
if RequestStore.active? && RequestStore.store[:peek_enabled]
- track_query(data[:sql].strip, data[:binds], start, finish)
+ # data[:cached] is only available starting from Rails 5.1.0
+ # https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb#L113
+ # Before that, data[:name] was set to 'CACHE'
+ # https://github.com/rails/rails/blob/v4.2.9/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb#L80
+ unless data.fetch(:cached, data[:name] == 'CACHE')
+ track_query(data[:sql].strip, data[:binds], start, finish)
+ end
end
end
end