aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorEileen Uchitelle <eileencodes@gmail.com>2018-06-12 15:36:54 -0400
committerEileen Uchitelle <eileencodes@gmail.com>2018-06-12 15:37:23 -0400
commite0874b6f88509270d7603184ecd158d55df7204f (patch)
tree3fce037f95b5e951c63014437cbdbdb512f54f08 /activerecord/lib
parent39cb84e8bdd4b9a35d68b33222a174d2350aee89 (diff)
downloadrails-e0874b6f88509270d7603184ecd158d55df7204f.tar.gz
rails-e0874b6f88509270d7603184ecd158d55df7204f.tar.bz2
rails-e0874b6f88509270d7603184ecd158d55df7204f.zip
Add ability to configure cache notifications info
This may seem like an unnecessary refactoring but some apps want / need to configure the information passed to the query cache logger. In order to do that we can add a method here that can be easily overridden by the app itself, rather than hacking the query cache logger to include that information. To override apps can call ``` def cache_notifications_info super.merge(connected_host: "hostname") end ``` This will take what's already in the query cache logger and add `@something="yea"` to the object. At GitHub we use this to log the number of queries that are cached, the connection host and the connection url.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
index 25622e34c8..8aeb934ec2 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -110,12 +110,7 @@ module ActiveRecord
if @query_cache[sql].key?(binds)
ActiveSupport::Notifications.instrument(
"sql.active_record",
- sql: sql,
- binds: binds,
- type_casted_binds: -> { type_casted_binds(binds) },
- name: name,
- connection_id: object_id,
- cached: true,
+ cache_notification_info(sql, name, binds)
)
@query_cache[sql][binds]
else
@@ -125,6 +120,19 @@ module ActiveRecord
end
end
+ # Database adapters can override this method to
+ # provide custom cache information.
+ def cache_notification_info(sql, name, binds)
+ {
+ sql: sql,
+ binds: binds,
+ type_casted_binds: -> { type_casted_binds(binds) },
+ name: name,
+ connection_id: object_id,
+ cached: true
+ }
+ end
+
# If arel is locked this is a SELECT ... FOR UPDATE or somesuch. Such
# queries should not be cached.
def locked?(arel)