summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-07-17 16:44:00 +0200
committerRémy Coutable <remy@rymai.me>2017-07-17 16:44:00 +0200
commit32eaf46ead7d704e7f740e3e793281134239b328 (patch)
tree028bdeae7716d599621d3cd9c07455fedcf34fe2
parent1bd140ca3afae608d07be7d2f004d71a5d19c10f (diff)
downloadgitlab-ce-32eaf46ead7d704e7f740e3e793281134239b328.tar.gz
Don't track cached queries in Gitlab::PerformanceBar::PeekQueryTracker34940-peek-performance-bar-doesn-t-count-cached-queries-but-shows-them
Signed-off-by: Rémy Coutable <remy@rymai.me>
-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